Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sitecore-cloudsdk/events

Package Overview
Dependencies
Maintainers
0
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sitecore-cloudsdk/events - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1-rc.0

2

dist/cjs/package.json
{
"name": "@sitecore-cloudsdk/events",
"version": "0.3.0",
"version": "0.3.1-rc.0",
"license": "Apache-2.0",

@@ -5,0 +5,0 @@ "homepage": "https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html",

@@ -5,2 +5,6 @@ /**

export declare const LIBRARY_VERSION: string;
/**
* Returns the name & version of the library in a String.
*/
export declare const X_CLIENT_SOFTWARE_ID: string;
export declare enum ErrorMessages {

@@ -7,0 +11,0 @@ IE_0001 = "[IE-0001] The \"window\" object is not available on the server side. Use the \"window\" object only on the client side, and in the correct execution context.",

@@ -6,7 +6,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.EVENTS_NAMESPACE = exports.ErrorMessages = exports.LIBRARY_VERSION = void 0;
exports.EVENTS_NAMESPACE = exports.ErrorMessages = exports.X_CLIENT_SOFTWARE_ID = exports.LIBRARY_VERSION = void 0;
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
/* eslint-disable @typescript-eslint/naming-convention */
const consts_1 = require("./events/consts");
const package_json_1 = __importDefault(require("../../package.json"));
const consts_1 = require("./events/consts");
/**

@@ -16,2 +16,7 @@ * Returns the version of the library.

exports.LIBRARY_VERSION = package_json_1.default.version;
/**
* Returns the name & version of the library in a String.
*/
exports.X_CLIENT_SOFTWARE_ID = `${package_json_1.default.name} ${exports.LIBRARY_VERSION}`;
/* eslint-disable max-len */
var ErrorMessages;

@@ -28,2 +33,3 @@ (function (ErrorMessages) {

})(ErrorMessages || (exports.ErrorMessages = ErrorMessages = {}));
/* eslint-enable max-len */
exports.EVENTS_NAMESPACE = 'sitecore-cloudsdk:events';

@@ -1,2 +0,2 @@

import { EventAttributesInput } from './common-interfaces';
import type { EventAttributesInput } from './common-interfaces';
export declare class BaseEvent {

@@ -32,4 +32,5 @@ private baseEventData;

pos: string;
requested_at: string;
}
type BaseEventData = EventAttributesInput;
export {};

@@ -26,6 +26,5 @@ "use strict";

return {
// eslint-disable-next-line @typescript-eslint/naming-convention
/* eslint-disable @typescript-eslint/naming-convention */
browser_id: this.browserId,
channel: this.baseEventData.channel,
/* eslint-disable @typescript-eslint/naming-convention */
client_key: '',

@@ -36,2 +35,4 @@ currency: this.baseEventData.currency,

pos: '',
requested_at: new Date().toISOString()
/* eslint-enable @typescript-eslint/naming-convention */
};

@@ -38,0 +39,0 @@ }

@@ -1,2 +0,2 @@

import { NestedObject } from '@sitecore-cloudsdk/utils';
import type { NestedObject } from '@sitecore-cloudsdk/utils';
/**

@@ -3,0 +3,0 @@ * Event data that is sent to Sitecore EP

@@ -0,6 +1,6 @@

import type { BasicTypes, NestedObject } from '@sitecore-cloudsdk/utils';
import type { EPResponse, Settings } from '@sitecore-cloudsdk/core';
import type { EventAttributesInput, ExtensionData } from '../common-interfaces';
import { BaseEvent } from '../base-event';
import { EventAttributesInput, ExtensionData } from '../common-interfaces';
import { SendEvent } from '../send-event/sendEvent';
import { EPResponse, Settings } from '@sitecore-cloudsdk/core';
import { BasicTypes, NestedObject } from '@sitecore-cloudsdk/utils';
import type { SendEvent } from '../send-event/sendEvent';
export declare class CustomEvent extends BaseEvent {

@@ -35,2 +35,8 @@ customEventPayload: CustomEventPayload;

export interface CustomEventPayload extends NestedObject {
sc_search?: {
data: NestedObject;
metadata: {
ut_api_version: string;
};
};
ext?: {

@@ -45,3 +51,4 @@ [key: string]: BasicTypes;

type: string;
searchData?: NestedObject;
extensionData?: ExtensionData;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomEvent = void 0;
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
const base_event_1 = require("../base-event");
const consts_1 = require("../../consts");
const consts_2 = require("../consts");
const utils_1 = require("@sitecore-cloudsdk/utils");
const consts_1 = require("../consts");
const consts_2 = require("../../consts");
class CustomEvent extends base_event_1.BaseEvent {

@@ -15,3 +14,3 @@ /**

constructor(args) {
const { channel, currency, language, page, type, extensionData, ...rest } = args.eventData;
const { channel, currency, language, page, type, extensionData, searchData, ...rest } = args.eventData;
super({ channel, currency, language, page }, args.id);

@@ -23,3 +22,3 @@ this.extensionData = {};

type,
...rest,
...rest
};

@@ -29,6 +28,14 @@ if (extensionData)

const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
if (numberOfExtensionDataProperties > consts_1.MAX_EXT_ATTRIBUTES)
throw new Error(consts_2.ErrorMessages.IV_0005);
if (numberOfExtensionDataProperties > consts_2.MAX_EXT_ATTRIBUTES)
throw new Error(consts_1.ErrorMessages.IV_0005);
if (numberOfExtensionDataProperties > 0)
this.customEventPayload.ext = this.extensionData;
if (searchData)
this.customEventPayload.sc_search = {
data: searchData,
metadata: {
// eslint-disable-next-line @typescript-eslint/naming-convention
ut_api_version: '1.0'
}
};
}

@@ -35,0 +42,0 @@ /**

@@ -1,3 +0,3 @@

import { EPResponse } from '@sitecore-cloudsdk/core';
import { EventData } from './custom-event';
import type { EPResponse } from '@sitecore-cloudsdk/core';
import type { EventData } from './custom-event';
/**

@@ -4,0 +4,0 @@ * A function that sends an event to SitecoreCloud API with the specified type

@@ -7,5 +7,5 @@ "use strict";

const custom_event_1 = require("./custom-event");
const consts_1 = require("../../consts");
const initializer_1 = require("../../initializer/browser/initializer");
const sendEvent_1 = require("../send-event/sendEvent");
const consts_1 = require("../../consts");
/**

@@ -25,5 +25,5 @@ * A function that sends an event to SitecoreCloud API with the specified type

sendEvent: sendEvent_1.sendEvent,
settings,
settings
}).send();
}
exports.event = event;

@@ -1,4 +0,4 @@

import { EPResponse } from '@sitecore-cloudsdk/core';
import { EventData } from './custom-event';
import { Request } from '@sitecore-cloudsdk/utils';
import type { EPResponse } from '@sitecore-cloudsdk/core';
import type { EventData } from './custom-event';
import type { Request } from '@sitecore-cloudsdk/utils';
/**

@@ -5,0 +5,0 @@ * A function that sends an event to SitecoreCloud API with the specified type

@@ -7,4 +7,4 @@ "use strict";

const custom_event_1 = require("./custom-event");
const consts_1 = require("../../consts");
const sendEvent_1 = require("../send-event/sendEvent");
const consts_1 = require("../../consts");
/**

@@ -19,3 +19,3 @@ * A function that sends an event to SitecoreCloud API with the specified type

const settings = (0, core_1.handleGetSettingsError)(core_1.getSettingsServer, consts_1.ErrorMessages.IE_0005);
const id = (0, core_1.getBrowserIdFromRequest)(request, settings.cookieSettings.cookieName);
const id = (0, core_1.getCookieValueFromRequest)(request, settings.cookieSettings.cookieNames.browserId);
return new custom_event_1.CustomEvent({

@@ -25,5 +25,5 @@ eventData,

sendEvent: sendEvent_1.sendEvent,
settings,
settings
}).send();
}
exports.eventServer = eventServer;

@@ -1,2 +0,2 @@

import { EPResponse } from '@sitecore-cloudsdk/core';
import type { EPResponse } from '@sitecore-cloudsdk/core';
/**

@@ -3,0 +3,0 @@ * A function that sends a form event to SitecoreCloud API

@@ -7,5 +7,5 @@ "use strict";

const custom_event_1 = require("./custom-event");
const consts_1 = require("../../consts");
const initializer_1 = require("../../initializer/browser/initializer");
const sendEvent_1 = require("../send-event/sendEvent");
const initializer_1 = require("../../initializer/browser/initializer");
const consts_1 = require("../../consts");
/**

@@ -27,9 +27,9 @@ * A function that sends a form event to SitecoreCloud API

formId,
interactionType: interactionType.toUpperCase(),
interactionType: interactionType.toUpperCase()
},
type: 'FORM',
type: 'FORM'
},
id,
sendEvent: sendEvent_1.sendEvent,
settings,
settings
});

@@ -36,0 +36,0 @@ formEvent.page = undefined;

@@ -0,6 +1,6 @@

import type { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
import type { EventAttributesInput, ExtensionData } from '../common-interfaces';
import { BaseEvent } from '../base-event';
import { ExtensionData, EventAttributesInput } from '../common-interfaces';
import { FlattenedObject } from '@sitecore-cloudsdk/utils';
import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
import { SendEvent } from '../send-event/sendEvent';
import type { FlattenedObject } from '@sitecore-cloudsdk/utils';
import type { SendEvent } from '../send-event/sendEvent';
export declare class IdentityEvent extends BaseEvent {

@@ -7,0 +7,0 @@ private identityData;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IdentityEvent = void 0;
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
const utils_1 = require("@sitecore-cloudsdk/utils");
const base_event_1 = require("../base-event");
const consts_1 = require("../consts");
const utils_1 = require("@sitecore-cloudsdk/utils");
const consts_2 = require("../../consts");
const consts_1 = require("../../consts");
const consts_2 = require("../consts");
class IdentityEvent extends base_event_1.BaseEvent {

@@ -27,4 +26,4 @@ /**

this.numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
if (this.numberOfExtensionDataProperties > consts_1.MAX_EXT_ATTRIBUTES)
throw new Error(consts_2.ErrorMessages.IV_0005);
if (this.numberOfExtensionDataProperties > consts_2.MAX_EXT_ATTRIBUTES)
throw new Error(consts_1.ErrorMessages.IV_0005);
}

@@ -37,11 +36,11 @@ /**

if (identityData.identifiers.length === 0)
throw new Error(consts_2.ErrorMessages.MV_0003);
throw new Error(consts_1.ErrorMessages.MV_0003);
if (identityData.dob !== undefined && !(0, utils_1.isShortISODateString)(identityData.dob))
throw new Error(consts_2.ErrorMessages.IV_0002);
throw new Error(consts_1.ErrorMessages.IV_0002);
identityData.identifiers.forEach((identifier) => {
if (identifier.expiryDate && !(0, utils_1.isShortISODateString)(identifier.expiryDate))
throw new Error(consts_2.ErrorMessages.IV_0004);
throw new Error(consts_1.ErrorMessages.IV_0004);
});
if (identityData.email && !(0, utils_1.isValidEmail)(identityData.email))
throw new Error(consts_2.ErrorMessages.IV_0003);
throw new Error(consts_1.ErrorMessages.IV_0003);
}

@@ -65,3 +64,3 @@ /**

id: value.id,
provider: value.provider,
provider: value.provider
};

@@ -77,3 +76,3 @@ }),

title: this.identityData.title,
type: 'IDENTITY',
type: 'IDENTITY'
};

@@ -80,0 +79,0 @@ if (this.numberOfExtensionDataProperties > 0)

@@ -1,3 +0,3 @@

import { EPResponse } from '@sitecore-cloudsdk/core';
import { IdentityData } from './identity-event';
import type { EPResponse } from '@sitecore-cloudsdk/core';
import type { IdentityData } from './identity-event';
/**

@@ -4,0 +4,0 @@ * A function that sends an IDENTITY event to SitecoreCloud API

@@ -6,6 +6,6 @@ "use strict";

const core_1 = require("@sitecore-cloudsdk/core");
const consts_1 = require("../../consts");
const identity_event_1 = require("./identity-event");
const initializer_1 = require("../../initializer/browser/initializer");
const sendEvent_1 = require("../send-event/sendEvent");
const consts_1 = require("../../consts");
/**

@@ -25,5 +25,5 @@ * A function that sends an IDENTITY event to SitecoreCloud API

sendEvent: sendEvent_1.sendEvent,
settings,
settings
}).send();
}
exports.identity = identity;

@@ -1,4 +0,4 @@

import { Request } from '@sitecore-cloudsdk/utils';
import { EPResponse } from '@sitecore-cloudsdk/core';
import { IdentityData } from './identity-event';
import type { EPResponse } from '@sitecore-cloudsdk/core';
import type { IdentityData } from './identity-event';
import type { Request } from '@sitecore-cloudsdk/utils';
/**

@@ -5,0 +5,0 @@ * A function that sends an IDENTITY event to SitecoreCloud API

@@ -6,5 +6,5 @@ "use strict";

const core_1 = require("@sitecore-cloudsdk/core");
const consts_1 = require("../../consts");
const identity_event_1 = require("./identity-event");
const sendEvent_1 = require("../send-event/sendEvent");
const consts_1 = require("../../consts");
/**

@@ -19,3 +19,3 @@ * A function that sends an IDENTITY event to SitecoreCloud API

const settings = (0, core_1.handleGetSettingsError)(core_1.getSettingsServer, consts_1.ErrorMessages.IE_0005);
const id = (0, core_1.getBrowserIdFromRequest)(request, settings.cookieSettings.cookieName);
const id = (0, core_1.getCookieValueFromRequest)(request, settings.cookieSettings.cookieNames.browserId);
return new identity_event_1.IdentityEvent({

@@ -25,5 +25,5 @@ id,

sendEvent: sendEvent_1.sendEvent,
settings: settings,
settings: settings
}).send();
}
exports.identityServer = identityServer;

@@ -1,10 +0,10 @@

import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
import { FlattenedObject, NestedObject } from '@sitecore-cloudsdk/utils';
import type { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
import type { EventAttributesInput, ExtensionData } from '../common-interfaces';
import type { FlattenedObject, NestedObject } from '@sitecore-cloudsdk/utils';
import { BaseEvent } from '../base-event';
import { EventAttributesInput, ExtensionData } from '../common-interfaces';
import { SendEvent } from '../send-event/sendEvent';
import type { SendEvent } from '../send-event/sendEvent';
export declare class PageViewEvent extends BaseEvent {
static isFirstPageView: boolean;
private sendEvent;
private pageViewData;
private pageViewData?;
private extensionData;

@@ -52,3 +52,3 @@ private urlSearchParams;

sendEvent: SendEvent;
pageViewData: PageViewData;
pageViewData?: PageViewData;
id: string;

@@ -68,2 +68,3 @@ settings: Settings;

extensionData?: ExtensionData;
searchData?: NestedObject;
}

@@ -85,3 +86,9 @@ /**

} & FlattenedObject;
sc_search?: {
data: NestedObject;
metadata: {
ut_api_version: string;
};
};
}
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PageViewEvent = void 0;
const utils_1 = require("@sitecore-cloudsdk/utils");
const consts_1 = require("../consts");
const base_event_1 = require("../base-event");
const consts_1 = require("../consts");
const consts_2 = require("../../consts");
const utils_1 = require("@sitecore-cloudsdk/utils");
class PageViewEvent extends base_event_1.BaseEvent {

@@ -14,3 +14,3 @@ /**

constructor(args) {
const { channel, currency, language, page, extensionData } = args.pageViewData;
const { channel, currency, language, page, extensionData } = { ...args.pageViewData };
super({

@@ -20,3 +20,3 @@ channel,

language,
page,
page
}, args.id);

@@ -33,4 +33,3 @@ this.extensionData = {};

throw new Error(consts_2.ErrorMessages.IV_0005);
this.includeUTMParameters =
args.pageViewData.includeUTMParameters === undefined ? true : args.pageViewData.includeUTMParameters;
this.includeUTMParameters = (args.pageViewData && args.pageViewData.includeUTMParameters) ?? true;
}

@@ -58,3 +57,3 @@ /**

getReferrer() {
if (this.pageViewData.referrer)
if (this.pageViewData?.referrer)
return this.pageViewData.referrer;

@@ -73,20 +72,29 @@ if (typeof window === 'undefined')

mapAttributes() {
let viewPayload = {
type: 'VIEW',
let pageViewPayload = {
type: 'VIEW'
};
const pageVariantId = this.getPageVariantId(this.pageViewData.pageVariantId, this.extensionData['pageVariantId']);
const pageVariantId = this.pageViewData &&
this.getPageVariantId(this.pageViewData.pageVariantId, this.extensionData['pageVariantId']);
if (pageVariantId !== null)
viewPayload.ext = { ...viewPayload.ext, pageVariantId };
pageViewPayload.ext = { ...pageViewPayload.ext, pageVariantId };
if (Object.keys(this.extensionData).length > 0) {
delete this.extensionData['pageVariantId'];
viewPayload.ext = { ...viewPayload.ext, ...this.extensionData };
pageViewPayload.ext = { ...pageViewPayload.ext, ...this.extensionData };
}
if (this.includeUTMParameters) {
const utmParameters = this.getUTMParameters();
viewPayload = { ...viewPayload, ...utmParameters };
pageViewPayload = { ...pageViewPayload, ...utmParameters };
}
const referrer = this.getReferrer();
if (referrer !== null)
viewPayload = { ...viewPayload, referrer };
return viewPayload;
pageViewPayload = { ...pageViewPayload, referrer };
if (this.pageViewData?.searchData)
pageViewPayload.sc_search = {
data: this.pageViewData.searchData,
metadata: {
// eslint-disable-next-line @typescript-eslint/naming-convention
ut_api_version: '1.0'
}
};
return pageViewPayload;
}

@@ -100,5 +108,4 @@ /**

const eventAttrs = this.mapAttributes();
const fetchBody = Object.assign({}, eventAttrs, baseAttr);
PageViewEvent.isFirstPageView = false;
return await this.sendEvent(fetchBody, this.settings);
return await this.sendEvent({ ...baseAttr, ...eventAttrs }, this.settings);
}

@@ -105,0 +112,0 @@ /**

@@ -1,4 +0,4 @@

import { EPResponse } from '@sitecore-cloudsdk/core';
import { Request } from '@sitecore-cloudsdk/utils';
import { PageViewData } from './page-view-event';
import type { EPResponse } from '@sitecore-cloudsdk/core';
import type { PageViewData } from './page-view-event';
import type { Request } from '@sitecore-cloudsdk/utils';
/**

@@ -11,2 +11,2 @@ * A function that sends a VIEW event to SitecoreCloud API

*/
export declare function pageViewServer<T extends Request>(request: T, pageViewData: PageViewData): Promise<EPResponse | null>;
export declare function pageViewServer<T extends Request>(request: T, pageViewData?: PageViewData): Promise<EPResponse | null>;

@@ -6,5 +6,5 @@ "use strict";

const core_1 = require("@sitecore-cloudsdk/core");
const consts_1 = require("../../consts");
const page_view_event_1 = require("./page-view-event");
const sendEvent_1 = require("../send-event/sendEvent");
const consts_1 = require("../../consts");
/**

@@ -19,3 +19,3 @@ * A function that sends a VIEW event to SitecoreCloud API

const settings = (0, core_1.handleGetSettingsError)(core_1.getSettingsServer, consts_1.ErrorMessages.IE_0005);
const id = (0, core_1.getBrowserIdFromRequest)(request, settings.cookieSettings.cookieName);
const id = (0, core_1.getCookieValueFromRequest)(request, settings.cookieSettings.cookieNames.browserId);
// Host is irrelevant but necessary to support relative URL

@@ -28,5 +28,5 @@ const requestUrl = new URL(request.url, `https://localhost`);

sendEvent: sendEvent_1.sendEvent,
settings,
settings
}).send();
}
exports.pageViewServer = pageViewServer;

@@ -1,10 +0,10 @@

import { EPResponse } from '@sitecore-cloudsdk/core';
import { PageViewData } from './page-view-event';
import type { EPResponse } from '@sitecore-cloudsdk/core';
import type { PageViewData } from './page-view-event';
/**
* A function that sends a VIEW event to SitecoreCloud API
*
* @param pageViewData - The required/optional attributes in order to be send to SitecoreCloud API
* @param pageViewData - The optional attributes in order to be send to SitecoreCloud API
* This object will be flattened and sent in the ext object of the payload
* @returns The response object that Sitecore EP returns
*/
export declare function pageView(pageViewData: PageViewData): Promise<EPResponse | null>;
export declare function pageView(pageViewData?: PageViewData): Promise<EPResponse | null>;

@@ -6,10 +6,10 @@ "use strict";

const core_1 = require("@sitecore-cloudsdk/core");
const consts_1 = require("../../consts");
const page_view_event_1 = require("./page-view-event");
const initializer_1 = require("../../initializer/browser/initializer");
const sendEvent_1 = require("../send-event/sendEvent");
const consts_1 = require("../../consts");
/**
* A function that sends a VIEW event to SitecoreCloud API
*
* @param pageViewData - The required/optional attributes in order to be send to SitecoreCloud API
* @param pageViewData - The optional attributes in order to be send to SitecoreCloud API
* This object will be flattened and sent in the ext object of the payload

@@ -27,5 +27,5 @@ * @returns The response object that Sitecore EP returns

sendEvent: sendEvent_1.sendEvent,
settings,
settings
}).send();
}
exports.pageView = pageView;

@@ -1,3 +0,3 @@

import { EPResponse, Settings } from '@sitecore-cloudsdk/core';
import type { BasePayload, PageViewEventPayload, IdentityEventPayload, CustomEventPayload } from '..';
import type { BasePayload, CustomEventPayload, IdentityEventPayload, PageViewEventPayload } from '..';
import type { EPResponse, Settings } from '@sitecore-cloudsdk/core';
/**

@@ -4,0 +4,0 @@ * This factory function sends an event to Edge Proxy

"use strict";
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendEvent = void 0;
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
const core_1 = require("@sitecore-cloudsdk/core");

@@ -13,12 +13,16 @@ const consts_1 = require("../../consts");

async function sendEvent(body, settings) {
// eslint-disable-next-line max-len
const eventUrl = `${settings.sitecoreEdgeUrl}/v1/events/${core_1.API_VERSION}/events?sitecoreContextId=${settings.sitecoreEdgeContextId}&siteId=${settings.siteName}`;
const startTimestamp = Date.now();
let debugResponse = {};
const fetchOptions = {
body: JSON.stringify(body),
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention
/* eslint-disable @typescript-eslint/naming-convention */
'Content-Type': 'application/json',
// eslint-disable-next-line @typescript-eslint/naming-convention
'X-Library-Version': consts_1.LIBRARY_VERSION,
'X-Client-Software-ID': consts_1.X_CLIENT_SOFTWARE_ID,
'X-Library-Version': consts_1.LIBRARY_VERSION
/* eslint-enable @typescript-eslint/naming-convention */
},
method: 'POST',
method: 'POST'
};

@@ -28,7 +32,8 @@ (0, core_1.debug)(consts_1.EVENTS_NAMESPACE)('Events request: %s with options: %O', eventUrl, fetchOptions);

.then((response) => {
(0, core_1.debug)(consts_1.EVENTS_NAMESPACE)('Events response: %O', response);
debugResponse = (0, core_1.processDebugResponse)(consts_1.EVENTS_NAMESPACE, response);
return response.json();
})
.then((data) => {
(0, core_1.debug)(consts_1.EVENTS_NAMESPACE)('Events payload: %O', data);
debugResponse.body = data;
(0, core_1.debug)(consts_1.EVENTS_NAMESPACE)('Events response in %dms : %O', Date.now() - startTimestamp, debugResponse);
return data;

@@ -35,0 +40,0 @@ })

@@ -1,2 +0,2 @@

import { EventData } from '../events';
import type { EventData } from '../events';
/**

@@ -3,0 +3,0 @@ * A function that adds event to the queue

@@ -5,6 +5,6 @@ "use strict";

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
const core_1 = require("@sitecore-cloudsdk/core");
const consts_1 = require("../consts");
const initializer_1 = require("../initializer/browser/initializer");
const eventStorage_1 = require("./eventStorage");
const core_1 = require("@sitecore-cloudsdk/core");
const consts_1 = require("../consts");
/**

@@ -22,3 +22,3 @@ * A function that adds event to the queue

id,
settings,
settings
};

@@ -25,0 +25,0 @@ eventStorage_1.eventQueue.enqueueEvent(queueEventPayload);

@@ -1,2 +0,2 @@

import { CustomEventArguments } from '../events';
import type { CustomEventArguments } from '../events';
declare class EventQueue {

@@ -3,0 +3,0 @@ /**

@@ -38,3 +38,3 @@ "use strict";

sendEvent: sendEvent_1.sendEvent,
...queueEventPayload,
...queueEventPayload
});

@@ -50,3 +50,3 @@ const eventQueue = this.getEventQueue();

const eventQueue = this.getEventQueue();
for (const queueEventPayload of eventQueue) {
for (const queueEventPayload of eventQueue)
await new events_1.CustomEvent({

@@ -56,5 +56,4 @@ eventData: queueEventPayload.eventData,

sendEvent: sendEvent_1.sendEvent,
settings: queueEventPayload.settings,
settings: queueEventPayload.settings
}).send();
}
this.clearQueue();

@@ -61,0 +60,0 @@ }

@@ -5,5 +5,5 @@ "use strict";

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
const core_1 = require("@sitecore-cloudsdk/core");
const consts_1 = require("../consts");
const initializer_1 = require("../initializer/browser/initializer");
const core_1 = require("@sitecore-cloudsdk/core");
/**

@@ -10,0 +10,0 @@ * A function that returns the guest id.

@@ -1,3 +0,15 @@

import { BrowserSettings } from '@sitecore-cloudsdk/core';
import type { BrowserSettings } from '@sitecore-cloudsdk/core';
export declare let initPromise: Promise<void> | null;
declare global {
interface Window {
Engage: {
[x: string]: any;
getBrowserId?: () => string;
versions?: {
personalize?: string;
events?: string;
};
};
}
}
/**

@@ -4,0 +16,0 @@ * Initiates the Events library using the global settings added by the developer

@@ -5,4 +5,4 @@ "use strict";

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
const consts_1 = require("../../consts");
const core_1 = require("@sitecore-cloudsdk/core");
const consts_1 = require("../../consts");
exports.initPromise = null;

@@ -32,4 +32,4 @@ /**

...window.Engage?.versions,
events: consts_1.LIBRARY_VERSION,
},
events: consts_1.LIBRARY_VERSION
}
};

@@ -36,0 +36,0 @@ }

@@ -1,3 +0,3 @@

import { ServerSettings } from '@sitecore-cloudsdk/core';
import { HttpResponse, MiddlewareNextResponse, Request } from '@sitecore-cloudsdk/utils';
import type { Request, Response } from '@sitecore-cloudsdk/utils';
import type { ServerSettings } from '@sitecore-cloudsdk/core';
/**

@@ -10,2 +10,2 @@ * Initiates the server Events library using the global settings added by the developer

*/
export declare function initServer<Response extends MiddlewareNextResponse | HttpResponse>(request: Request, response: Response, settings: ServerSettings): Promise<void>;
export declare function initServer(request: Request, response: Response, settings: ServerSettings): Promise<void>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.initServer = void 0;
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
const core_1 = require("@sitecore-cloudsdk/core");

@@ -6,0 +5,0 @@ const consts_1 = require("../../consts");

{
"name": "@sitecore-cloudsdk/events",
"version": "0.3.0",
"version": "0.3.1-rc.0",
"license": "Apache-2.0",

@@ -5,0 +5,0 @@ "homepage": "https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html",

@@ -5,2 +5,6 @@ /**

export declare const LIBRARY_VERSION: string;
/**
* Returns the name & version of the library in a String.
*/
export declare const X_CLIENT_SOFTWARE_ID: string;
export declare enum ErrorMessages {

@@ -7,0 +11,0 @@ IE_0001 = "[IE-0001] The \"window\" object is not available on the server side. Use the \"window\" object only on the client side, and in the correct execution context.",

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
/* eslint-disable @typescript-eslint/naming-convention */
import { MAX_EXT_ATTRIBUTES } from './events/consts';
import packageJson from '../../package.json';
import { MAX_EXT_ATTRIBUTES } from './events/consts';
/**

@@ -9,2 +9,7 @@ * Returns the version of the library.

export const LIBRARY_VERSION = packageJson.version;
/**
* Returns the name & version of the library in a String.
*/
export const X_CLIENT_SOFTWARE_ID = `${packageJson.name} ${LIBRARY_VERSION}`;
/* eslint-disable max-len */
export var ErrorMessages;

@@ -21,2 +26,3 @@ (function (ErrorMessages) {

})(ErrorMessages || (ErrorMessages = {}));
/* eslint-enable max-len */
export const EVENTS_NAMESPACE = 'sitecore-cloudsdk:events';

@@ -1,2 +0,2 @@

import { EventAttributesInput } from './common-interfaces';
import type { EventAttributesInput } from './common-interfaces';
export declare class BaseEvent {

@@ -32,4 +32,5 @@ private baseEventData;

pos: string;
requested_at: string;
}
type BaseEventData = EventAttributesInput;
export {};

@@ -23,6 +23,5 @@ // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.

return {
// eslint-disable-next-line @typescript-eslint/naming-convention
/* eslint-disable @typescript-eslint/naming-convention */
browser_id: this.browserId,
channel: this.baseEventData.channel,
/* eslint-disable @typescript-eslint/naming-convention */
client_key: '',

@@ -33,4 +32,6 @@ currency: this.baseEventData.currency,

pos: '',
requested_at: new Date().toISOString()
/* eslint-enable @typescript-eslint/naming-convention */
};
}
}

@@ -1,2 +0,2 @@

import { NestedObject } from '@sitecore-cloudsdk/utils';
import type { NestedObject } from '@sitecore-cloudsdk/utils';
/**

@@ -3,0 +3,0 @@ * Event data that is sent to Sitecore EP

@@ -0,6 +1,6 @@

import type { BasicTypes, NestedObject } from '@sitecore-cloudsdk/utils';
import type { EPResponse, Settings } from '@sitecore-cloudsdk/core';
import type { EventAttributesInput, ExtensionData } from '../common-interfaces';
import { BaseEvent } from '../base-event';
import { EventAttributesInput, ExtensionData } from '../common-interfaces';
import { SendEvent } from '../send-event/sendEvent';
import { EPResponse, Settings } from '@sitecore-cloudsdk/core';
import { BasicTypes, NestedObject } from '@sitecore-cloudsdk/utils';
import type { SendEvent } from '../send-event/sendEvent';
export declare class CustomEvent extends BaseEvent {

@@ -35,2 +35,8 @@ customEventPayload: CustomEventPayload;

export interface CustomEventPayload extends NestedObject {
sc_search?: {
data: NestedObject;
metadata: {
ut_api_version: string;
};
};
ext?: {

@@ -45,3 +51,4 @@ [key: string]: BasicTypes;

type: string;
searchData?: NestedObject;
extensionData?: ExtensionData;
}

@@ -1,6 +0,5 @@

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { BaseEvent } from '../base-event';
import { ErrorMessages } from '../../consts';
import { MAX_EXT_ATTRIBUTES } from '../consts';
import { flattenObject } from '@sitecore-cloudsdk/utils';
import { MAX_EXT_ATTRIBUTES } from '../consts';
import { ErrorMessages } from '../../consts';
export class CustomEvent extends BaseEvent {

@@ -12,3 +11,3 @@ /**

constructor(args) {
const { channel, currency, language, page, type, extensionData, ...rest } = args.eventData;
const { channel, currency, language, page, type, extensionData, searchData, ...rest } = args.eventData;
super({ channel, currency, language, page }, args.id);

@@ -20,3 +19,3 @@ this.extensionData = {};

type,
...rest,
...rest
};

@@ -30,2 +29,10 @@ if (extensionData)

this.customEventPayload.ext = this.extensionData;
if (searchData)
this.customEventPayload.sc_search = {
data: searchData,
metadata: {
// eslint-disable-next-line @typescript-eslint/naming-convention
ut_api_version: '1.0'
}
};
}

@@ -32,0 +39,0 @@ /**

@@ -1,3 +0,3 @@

import { EPResponse } from '@sitecore-cloudsdk/core';
import { EventData } from './custom-event';
import type { EPResponse } from '@sitecore-cloudsdk/core';
import type { EventData } from './custom-event';
/**

@@ -4,0 +4,0 @@ * A function that sends an event to SitecoreCloud API with the specified type

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
import { CustomEvent } from './custom-event';
import { ErrorMessages } from '../../consts';
import { awaitInit } from '../../initializer/browser/initializer';
import { sendEvent } from '../send-event/sendEvent';
import { ErrorMessages } from '../../consts';
/**

@@ -21,4 +21,4 @@ * A function that sends an event to SitecoreCloud API with the specified type

sendEvent,
settings,
settings
}).send();
}

@@ -1,4 +0,4 @@

import { EPResponse } from '@sitecore-cloudsdk/core';
import { EventData } from './custom-event';
import { Request } from '@sitecore-cloudsdk/utils';
import type { EPResponse } from '@sitecore-cloudsdk/core';
import type { EventData } from './custom-event';
import type { Request } from '@sitecore-cloudsdk/utils';
/**

@@ -5,0 +5,0 @@ * A function that sends an event to SitecoreCloud API with the specified type

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { getBrowserIdFromRequest, getSettingsServer, handleGetSettingsError, } from '@sitecore-cloudsdk/core';
import { getCookieValueFromRequest, getSettingsServer, handleGetSettingsError } from '@sitecore-cloudsdk/core';
import { CustomEvent } from './custom-event';
import { ErrorMessages } from '../../consts';
import { sendEvent } from '../send-event/sendEvent';
import { ErrorMessages } from '../../consts';
/**

@@ -15,3 +15,3 @@ * A function that sends an event to SitecoreCloud API with the specified type

const settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0005);
const id = getBrowserIdFromRequest(request, settings.cookieSettings.cookieName);
const id = getCookieValueFromRequest(request, settings.cookieSettings.cookieNames.browserId);
return new CustomEvent({

@@ -21,4 +21,4 @@ eventData,

sendEvent,
settings,
settings
}).send();
}

@@ -1,2 +0,2 @@

import { EPResponse } from '@sitecore-cloudsdk/core';
import type { EPResponse } from '@sitecore-cloudsdk/core';
/**

@@ -3,0 +3,0 @@ * A function that sends a form event to SitecoreCloud API

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
import { CustomEvent } from './custom-event';
import { ErrorMessages } from '../../consts';
import { awaitInit } from '../../initializer/browser/initializer';
import { sendEvent } from '../send-event/sendEvent';
import { awaitInit } from '../../initializer/browser/initializer';
import { ErrorMessages } from '../../consts';
/**

@@ -23,9 +23,9 @@ * A function that sends a form event to SitecoreCloud API

formId,
interactionType: interactionType.toUpperCase(),
interactionType: interactionType.toUpperCase()
},
type: 'FORM',
type: 'FORM'
},
id,
sendEvent,
settings,
settings
});

@@ -32,0 +32,0 @@ formEvent.page = undefined;

@@ -0,6 +1,6 @@

import type { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
import type { EventAttributesInput, ExtensionData } from '../common-interfaces';
import { BaseEvent } from '../base-event';
import { ExtensionData, EventAttributesInput } from '../common-interfaces';
import { FlattenedObject } from '@sitecore-cloudsdk/utils';
import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
import { SendEvent } from '../send-event/sendEvent';
import type { FlattenedObject } from '@sitecore-cloudsdk/utils';
import type { SendEvent } from '../send-event/sendEvent';
export declare class IdentityEvent extends BaseEvent {

@@ -7,0 +7,0 @@ private identityData;

@@ -1,6 +0,5 @@

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { flattenObject, isShortISODateString, isValidEmail } from '@sitecore-cloudsdk/utils';
import { BaseEvent } from '../base-event';
import { ErrorMessages } from '../../consts';
import { MAX_EXT_ATTRIBUTES } from '../consts';
import { isShortISODateString, isValidEmail, flattenObject } from '@sitecore-cloudsdk/utils';
import { ErrorMessages } from '../../consts';
export class IdentityEvent extends BaseEvent {

@@ -60,3 +59,3 @@ /**

id: value.id,
provider: value.provider,
provider: value.provider
};

@@ -72,3 +71,3 @@ }),

title: this.identityData.title,
type: 'IDENTITY',
type: 'IDENTITY'
};

@@ -75,0 +74,0 @@ if (this.numberOfExtensionDataProperties > 0)

@@ -1,3 +0,3 @@

import { EPResponse } from '@sitecore-cloudsdk/core';
import { IdentityData } from './identity-event';
import type { EPResponse } from '@sitecore-cloudsdk/core';
import type { IdentityData } from './identity-event';
/**

@@ -4,0 +4,0 @@ * A function that sends an IDENTITY event to SitecoreCloud API

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
import { ErrorMessages } from '../../consts';
import { IdentityEvent } from './identity-event';
import { awaitInit } from '../../initializer/browser/initializer';
import { sendEvent } from '../send-event/sendEvent';
import { ErrorMessages } from '../../consts';
/**

@@ -21,4 +21,4 @@ * A function that sends an IDENTITY event to SitecoreCloud API

sendEvent,
settings,
settings
}).send();
}

@@ -1,4 +0,4 @@

import { Request } from '@sitecore-cloudsdk/utils';
import { EPResponse } from '@sitecore-cloudsdk/core';
import { IdentityData } from './identity-event';
import type { EPResponse } from '@sitecore-cloudsdk/core';
import type { IdentityData } from './identity-event';
import type { Request } from '@sitecore-cloudsdk/utils';
/**

@@ -5,0 +5,0 @@ * A function that sends an IDENTITY event to SitecoreCloud API

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { getBrowserIdFromRequest, getSettingsServer, handleGetSettingsError, } from '@sitecore-cloudsdk/core';
import { getCookieValueFromRequest, getSettingsServer, handleGetSettingsError } from '@sitecore-cloudsdk/core';
import { ErrorMessages } from '../../consts';
import { IdentityEvent } from './identity-event';
import { sendEvent } from '../send-event/sendEvent';
import { ErrorMessages } from '../../consts';
/**

@@ -15,3 +15,3 @@ * A function that sends an IDENTITY event to SitecoreCloud API

const settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0005);
const id = getBrowserIdFromRequest(request, settings.cookieSettings.cookieName);
const id = getCookieValueFromRequest(request, settings.cookieSettings.cookieNames.browserId);
return new IdentityEvent({

@@ -21,4 +21,4 @@ id,

sendEvent,
settings: settings,
settings: settings
}).send();
}

@@ -1,10 +0,10 @@

import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
import { FlattenedObject, NestedObject } from '@sitecore-cloudsdk/utils';
import type { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
import type { EventAttributesInput, ExtensionData } from '../common-interfaces';
import type { FlattenedObject, NestedObject } from '@sitecore-cloudsdk/utils';
import { BaseEvent } from '../base-event';
import { EventAttributesInput, ExtensionData } from '../common-interfaces';
import { SendEvent } from '../send-event/sendEvent';
import type { SendEvent } from '../send-event/sendEvent';
export declare class PageViewEvent extends BaseEvent {
static isFirstPageView: boolean;
private sendEvent;
private pageViewData;
private pageViewData?;
private extensionData;

@@ -52,3 +52,3 @@ private urlSearchParams;

sendEvent: SendEvent;
pageViewData: PageViewData;
pageViewData?: PageViewData;
id: string;

@@ -68,2 +68,3 @@ settings: Settings;

extensionData?: ExtensionData;
searchData?: NestedObject;
}

@@ -85,3 +86,9 @@ /**

} & FlattenedObject;
sc_search?: {
data: NestedObject;
metadata: {
ut_api_version: string;
};
};
}
export {};

@@ -1,5 +0,5 @@

import { flattenObject } from '@sitecore-cloudsdk/utils';
import { MAX_EXT_ATTRIBUTES, UTM_PREFIX } from '../consts';
import { BaseEvent } from '../base-event';
import { MAX_EXT_ATTRIBUTES, UTM_PREFIX } from '../consts';
import { ErrorMessages } from '../../consts';
import { flattenObject } from '@sitecore-cloudsdk/utils';
export class PageViewEvent extends BaseEvent {

@@ -11,3 +11,3 @@ /**

constructor(args) {
const { channel, currency, language, page, extensionData } = args.pageViewData;
const { channel, currency, language, page, extensionData } = { ...args.pageViewData };
super({

@@ -17,3 +17,3 @@ channel,

language,
page,
page
}, args.id);

@@ -30,4 +30,3 @@ this.extensionData = {};

throw new Error(ErrorMessages.IV_0005);
this.includeUTMParameters =
args.pageViewData.includeUTMParameters === undefined ? true : args.pageViewData.includeUTMParameters;
this.includeUTMParameters = (args.pageViewData && args.pageViewData.includeUTMParameters) ?? true;
}

@@ -55,3 +54,3 @@ /**

getReferrer() {
if (this.pageViewData.referrer)
if (this.pageViewData?.referrer)
return this.pageViewData.referrer;

@@ -70,20 +69,29 @@ if (typeof window === 'undefined')

mapAttributes() {
let viewPayload = {
type: 'VIEW',
let pageViewPayload = {
type: 'VIEW'
};
const pageVariantId = this.getPageVariantId(this.pageViewData.pageVariantId, this.extensionData['pageVariantId']);
const pageVariantId = this.pageViewData &&
this.getPageVariantId(this.pageViewData.pageVariantId, this.extensionData['pageVariantId']);
if (pageVariantId !== null)
viewPayload.ext = { ...viewPayload.ext, pageVariantId };
pageViewPayload.ext = { ...pageViewPayload.ext, pageVariantId };
if (Object.keys(this.extensionData).length > 0) {
delete this.extensionData['pageVariantId'];
viewPayload.ext = { ...viewPayload.ext, ...this.extensionData };
pageViewPayload.ext = { ...pageViewPayload.ext, ...this.extensionData };
}
if (this.includeUTMParameters) {
const utmParameters = this.getUTMParameters();
viewPayload = { ...viewPayload, ...utmParameters };
pageViewPayload = { ...pageViewPayload, ...utmParameters };
}
const referrer = this.getReferrer();
if (referrer !== null)
viewPayload = { ...viewPayload, referrer };
return viewPayload;
pageViewPayload = { ...pageViewPayload, referrer };
if (this.pageViewData?.searchData)
pageViewPayload.sc_search = {
data: this.pageViewData.searchData,
metadata: {
// eslint-disable-next-line @typescript-eslint/naming-convention
ut_api_version: '1.0'
}
};
return pageViewPayload;
}

@@ -97,5 +105,4 @@ /**

const eventAttrs = this.mapAttributes();
const fetchBody = Object.assign({}, eventAttrs, baseAttr);
PageViewEvent.isFirstPageView = false;
return await this.sendEvent(fetchBody, this.settings);
return await this.sendEvent({ ...baseAttr, ...eventAttrs }, this.settings);
}

@@ -102,0 +109,0 @@ /**

@@ -1,4 +0,4 @@

import { EPResponse } from '@sitecore-cloudsdk/core';
import { Request } from '@sitecore-cloudsdk/utils';
import { PageViewData } from './page-view-event';
import type { EPResponse } from '@sitecore-cloudsdk/core';
import type { PageViewData } from './page-view-event';
import type { Request } from '@sitecore-cloudsdk/utils';
/**

@@ -11,2 +11,2 @@ * A function that sends a VIEW event to SitecoreCloud API

*/
export declare function pageViewServer<T extends Request>(request: T, pageViewData: PageViewData): Promise<EPResponse | null>;
export declare function pageViewServer<T extends Request>(request: T, pageViewData?: PageViewData): Promise<EPResponse | null>;
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { getBrowserIdFromRequest, getSettingsServer, handleGetSettingsError, } from '@sitecore-cloudsdk/core';
import { getCookieValueFromRequest, getSettingsServer, handleGetSettingsError } from '@sitecore-cloudsdk/core';
import { ErrorMessages } from '../../consts';
import { PageViewEvent } from './page-view-event';
import { sendEvent } from '../send-event/sendEvent';
import { ErrorMessages } from '../../consts';
/**

@@ -15,3 +15,3 @@ * A function that sends a VIEW event to SitecoreCloud API

const settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0005);
const id = getBrowserIdFromRequest(request, settings.cookieSettings.cookieName);
const id = getCookieValueFromRequest(request, settings.cookieSettings.cookieNames.browserId);
// Host is irrelevant but necessary to support relative URL

@@ -24,4 +24,4 @@ const requestUrl = new URL(request.url, `https://localhost`);

sendEvent,
settings,
settings
}).send();
}

@@ -1,10 +0,10 @@

import { EPResponse } from '@sitecore-cloudsdk/core';
import { PageViewData } from './page-view-event';
import type { EPResponse } from '@sitecore-cloudsdk/core';
import type { PageViewData } from './page-view-event';
/**
* A function that sends a VIEW event to SitecoreCloud API
*
* @param pageViewData - The required/optional attributes in order to be send to SitecoreCloud API
* @param pageViewData - The optional attributes in order to be send to SitecoreCloud API
* This object will be flattened and sent in the ext object of the payload
* @returns The response object that Sitecore EP returns
*/
export declare function pageView(pageViewData: PageViewData): Promise<EPResponse | null>;
export declare function pageView(pageViewData?: PageViewData): Promise<EPResponse | null>;
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
import { ErrorMessages } from '../../consts';
import { PageViewEvent } from './page-view-event';
import { awaitInit } from '../../initializer/browser/initializer';
import { sendEvent } from '../send-event/sendEvent';
import { ErrorMessages } from '../../consts';
/**
* A function that sends a VIEW event to SitecoreCloud API
*
* @param pageViewData - The required/optional attributes in order to be send to SitecoreCloud API
* @param pageViewData - The optional attributes in order to be send to SitecoreCloud API
* This object will be flattened and sent in the ext object of the payload

@@ -23,4 +23,4 @@ * @returns The response object that Sitecore EP returns

sendEvent,
settings,
settings
}).send();
}

@@ -1,3 +0,3 @@

import { EPResponse, Settings } from '@sitecore-cloudsdk/core';
import type { BasePayload, PageViewEventPayload, IdentityEventPayload, CustomEventPayload } from '..';
import type { BasePayload, CustomEventPayload, IdentityEventPayload, PageViewEventPayload } from '..';
import type { EPResponse, Settings } from '@sitecore-cloudsdk/core';
/**

@@ -4,0 +4,0 @@ * This factory function sends an event to Edge Proxy

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { API_VERSION, debug } from '@sitecore-cloudsdk/core';
import { LIBRARY_VERSION, EVENTS_NAMESPACE } from '../../consts';
import { API_VERSION, debug, processDebugResponse } from '@sitecore-cloudsdk/core';
import { EVENTS_NAMESPACE, LIBRARY_VERSION, X_CLIENT_SOFTWARE_ID } from '../../consts';
/**

@@ -10,12 +10,16 @@ * This factory function sends an event to Edge Proxy

export async function sendEvent(body, settings) {
// eslint-disable-next-line max-len
const eventUrl = `${settings.sitecoreEdgeUrl}/v1/events/${API_VERSION}/events?sitecoreContextId=${settings.sitecoreEdgeContextId}&siteId=${settings.siteName}`;
const startTimestamp = Date.now();
let debugResponse = {};
const fetchOptions = {
body: JSON.stringify(body),
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention
/* eslint-disable @typescript-eslint/naming-convention */
'Content-Type': 'application/json',
// eslint-disable-next-line @typescript-eslint/naming-convention
'X-Library-Version': LIBRARY_VERSION,
'X-Client-Software-ID': X_CLIENT_SOFTWARE_ID,
'X-Library-Version': LIBRARY_VERSION
/* eslint-enable @typescript-eslint/naming-convention */
},
method: 'POST',
method: 'POST'
};

@@ -25,7 +29,8 @@ debug(EVENTS_NAMESPACE)('Events request: %s with options: %O', eventUrl, fetchOptions);

.then((response) => {
debug(EVENTS_NAMESPACE)('Events response: %O', response);
debugResponse = processDebugResponse(EVENTS_NAMESPACE, response);
return response.json();
})
.then((data) => {
debug(EVENTS_NAMESPACE)('Events payload: %O', data);
debugResponse.body = data;
debug(EVENTS_NAMESPACE)('Events response in %dms : %O', Date.now() - startTimestamp, debugResponse);
return data;

@@ -32,0 +37,0 @@ })

@@ -1,2 +0,2 @@

import { EventData } from '../events';
import type { EventData } from '../events';
/**

@@ -3,0 +3,0 @@ * A function that adds event to the queue

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
import { ErrorMessages } from '../consts';
import { awaitInit } from '../initializer/browser/initializer';
import { eventQueue } from './eventStorage';
import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
import { ErrorMessages } from '../consts';
/**

@@ -18,5 +18,5 @@ * A function that adds event to the queue

id,
settings,
settings
};
eventQueue.enqueueEvent(queueEventPayload);
}

@@ -1,2 +0,2 @@

import { CustomEventArguments } from '../events';
import type { CustomEventArguments } from '../events';
declare class EventQueue {

@@ -3,0 +3,0 @@ /**

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { pageName, language } from '@sitecore-cloudsdk/core';
import { language, pageName } from '@sitecore-cloudsdk/core';
import { CustomEvent } from '../events';

@@ -35,3 +35,3 @@ import { sendEvent } from '../events/send-event/sendEvent';

sendEvent,
...queueEventPayload,
...queueEventPayload
});

@@ -47,3 +47,3 @@ const eventQueue = this.getEventQueue();

const eventQueue = this.getEventQueue();
for (const queueEventPayload of eventQueue) {
for (const queueEventPayload of eventQueue)
await new CustomEvent({

@@ -53,5 +53,4 @@ eventData: queueEventPayload.eventData,

sendEvent,
settings: queueEventPayload.settings,
settings: queueEventPayload.settings
}).send();
}
this.clearQueue();

@@ -58,0 +57,0 @@ }

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { getBrowserId, getGuestId as getGuestIdFromCore, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
import { ErrorMessages } from '../consts';
import { awaitInit } from '../initializer/browser/initializer';
import { getBrowserId, getGuestId as getGuestIdFromCore, getSettings, handleGetSettingsError, } from '@sitecore-cloudsdk/core';
/**

@@ -6,0 +6,0 @@ * A function that returns the guest id.

@@ -1,3 +0,15 @@

import { BrowserSettings } from '@sitecore-cloudsdk/core';
import type { BrowserSettings } from '@sitecore-cloudsdk/core';
export declare let initPromise: Promise<void> | null;
declare global {
interface Window {
Engage: {
[x: string]: any;
getBrowserId?: () => string;
versions?: {
personalize?: string;
events?: string;
};
};
}
}
/**

@@ -4,0 +16,0 @@ * Initiates the Events library using the global settings added by the developer

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { getBrowserId, initCore, debug } from '@sitecore-cloudsdk/core';
import { ErrorMessages, LIBRARY_VERSION, EVENTS_NAMESPACE } from '../../consts';
import { EVENTS_NAMESPACE, ErrorMessages, LIBRARY_VERSION } from '../../consts';
import { debug, getBrowserId, initCore } from '@sitecore-cloudsdk/core';
export let initPromise = null;

@@ -28,4 +28,4 @@ /**

...window.Engage?.versions,
events: LIBRARY_VERSION,
},
events: LIBRARY_VERSION
}
};

@@ -32,0 +32,0 @@ }

@@ -1,3 +0,3 @@

import { ServerSettings } from '@sitecore-cloudsdk/core';
import { HttpResponse, MiddlewareNextResponse, Request } from '@sitecore-cloudsdk/utils';
import type { Request, Response } from '@sitecore-cloudsdk/utils';
import type { ServerSettings } from '@sitecore-cloudsdk/core';
/**

@@ -10,2 +10,2 @@ * Initiates the server Events library using the global settings added by the developer

*/
export declare function initServer<Response extends MiddlewareNextResponse | HttpResponse>(request: Request, response: Response, settings: ServerSettings): Promise<void>;
export declare function initServer(request: Request, response: Response, settings: ServerSettings): Promise<void>;

@@ -1,3 +0,2 @@

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { initCoreServer, debug } from '@sitecore-cloudsdk/core';
import { debug, initCoreServer } from '@sitecore-cloudsdk/core';
import { EVENTS_NAMESPACE } from '../../consts';

@@ -4,0 +3,0 @@ /**

{
"name": "@sitecore-cloudsdk/events",
"version": "0.3.0",
"version": "0.3.1-rc.0",
"license": "Apache-2.0",

@@ -5,0 +5,0 @@ "homepage": "https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc