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

@sitecore-cloudsdk/events

Package Overview
Dependencies
Maintainers
3
Versions
26
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.2.4 to 0.3.0

11

dist/cjs/package.json
{
"name": "@sitecore-cloudsdk/events",
"version": "0.2.4",
"version": "0.3.0",
"license": "Apache-2.0",
"homepage": "https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-cloud-sdk.html",
"homepage": "https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html",
"exports": {

@@ -19,4 +19,4 @@ "./server": {

"dependencies": {
"@sitecore-cloudsdk/core": "^0.2.4",
"@sitecore-cloudsdk/utils": "^0.2.4"
"@sitecore-cloudsdk/core": "^0.3.0",
"@sitecore-cloudsdk/utils": "^0.3.0"
},

@@ -39,5 +39,4 @@ "scripts": {

"engines": {
"node": ">=18",
"npm": ">=9"
"node": ">=18"
}
}
export { getBrowserId } from '@sitecore-cloudsdk/core';
export { init } from './lib/initializer/browser/initializer';
export type { PageViewEventInput, CustomEventInput, IdentityEventAttributesInput } from './lib/events';
export type { PageViewData, EventData, IdentityData } from './lib/events';
export { addToEventQueue } from './lib/eventStorage/addToEventQueue';

@@ -5,0 +5,0 @@ export { processEventQueue } from './lib/eventStorage/processEventQueue';

@@ -12,5 +12,5 @@ /**

IV_0004 = "[IV-0004] Incorrect value for \"expiryDate\". Format the value according to ISO 8601.",
IV_0005 = "[IV-0005] This event supports maximum 50 attributes. Reduce the number of attributes.",
IV_0005 = "[IV-0005] \"extensionData\" supports maximum 50 attributes. Reduce the number of attributes.",
MV_0003 = "[MV-0003] \"identifiers\" is required."
}
export declare const EVENTS_NAMESPACE = "sitecore-cloudsdk:events";

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

ErrorMessages["IV_0004"] = "[IV-0004] Incorrect value for \"expiryDate\". Format the value according to ISO 8601.";
ErrorMessages["IV_0005"] = "[IV-0005] This event supports maximum 50 attributes. Reduce the number of attributes.";
ErrorMessages["IV_0005"] = "[IV-0005] \"extensionData\" supports maximum 50 attributes. Reduce the number of attributes.";
ErrorMessages["MV_0003"] = "[MV-0003] \"identifiers\" is required.";
})(ErrorMessages || (exports.ErrorMessages = ErrorMessages = {}));
exports.EVENTS_NAMESPACE = 'sitecore-cloudsdk:events';

@@ -33,3 +33,3 @@ import { EventAttributesInput } from './common-interfaces';

}
type BaseEventData = Partial<EventAttributesInput>;
type BaseEventData = EventAttributesInput;
export {};
import { NestedObject } from '@sitecore-cloudsdk/utils';
/**
* Event data received as input to be sent to Sitecore EP
*/
interface MandatoryInput {
channel: string;
currency: string;
}
type MandatoryEventInput = MandatoryInput;
/**
* Event data that is sent to Sitecore EP
*/
interface InferrableInput {
/**
* To be restored back to MandatoryEventInput Interface
* as mandatory input parameter in version 1.0.0
*/
export interface EventAttributesInput {
language?: string;
page?: string;
channel?: string;
currency?: string;
}
type InferrableEventInput = InferrableInput;
/**
* Interface to hold the base event attributes
*/
export interface EventAttributesInput extends MandatoryEventInput, InferrableEventInput {
}
/**
* Type of the extension data that the developer can pass to events
*/
export type ExtensionData = NestedObject;
export {};
import { BaseEvent } from '../base-event';
import { EventAttributesInput } from '../common-interfaces';
import { EventAttributesInput, ExtensionData } from '../common-interfaces';
import { SendEvent } from '../send-event/sendEvent';

@@ -27,7 +27,5 @@ import { EPResponse, Settings } from '@sitecore-cloudsdk/core';

sendEvent: SendEvent;
eventData: CustomEventData;
eventData: EventData;
id: string;
extensionData?: NestedObject;
settings: Settings;
type: string;
}

@@ -45,9 +43,5 @@ /**

*/
export interface CustomEventInput extends EventAttributesInput, NestedObject {
export interface EventData extends EventAttributesInput, NestedObject {
type: string;
extensionData?: ExtensionData;
}
/**
* Internal interface with the required/optional attributes in order to send a custom event to SitecoreCloud API
*/
interface CustomEventData extends Partial<EventAttributesInput>, NestedObject {
}
export {};

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

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

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

this.customEventPayload = {
type: args.type,
type,
...rest,
};
if (args.extensionData)
this.extensionData = (0, utils_1.flattenObject)({ object: args.extensionData });
if (extensionData)
this.extensionData = (0, utils_1.flattenObject)({ object: extensionData });
const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;

@@ -29,0 +29,0 @@ if (numberOfExtensionDataProperties > consts_1.MAX_EXT_ATTRIBUTES)

import { EPResponse } from '@sitecore-cloudsdk/core';
import { ExtensionData } from '../common-interfaces';
import { CustomEventInput } from './custom-event';
import { EventData } from './custom-event';
/**
* A function that sends an event to SitecoreCloud API with the specified type
* @param type - The required type of the event
*
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent 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 event(type: string, eventData: CustomEventInput, extensionData?: ExtensionData): Promise<EPResponse | null>;
export declare function event(eventData: EventData): Promise<EPResponse | null>;

@@ -12,9 +12,7 @@ "use strict";

* A function that sends an event to SitecoreCloud API with the specified type
* @param type - The required type of the event
*
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent 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
*/
async function event(type, eventData, extensionData) {
async function event(eventData) {
await (0, initializer_1.awaitInit)();

@@ -25,9 +23,7 @@ const settings = (0, core_1.handleGetSettingsError)(core_1.getSettings, consts_1.ErrorMessages.IE_0004);

eventData,
extensionData,
id,
sendEvent: sendEvent_1.sendEvent,
settings,
type,
}).send();
}
exports.event = event;
import { EPResponse } from '@sitecore-cloudsdk/core';
import { ExtensionData } from '../common-interfaces';
import { CustomEventInput } from './custom-event';
import { EventData } from './custom-event';
import { Request } from '@sitecore-cloudsdk/utils';
/**
* A function that sends an event to SitecoreCloud API with the specified type
* @param type - The required type of the event
*
* @param request - Interface with constraint for extending request
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param request - Interface with constraint for extending request
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* @returns The response object that Sitecore EP returns
*/
export declare function eventServer<T extends Request>(type: string, eventData: CustomEventInput, request: T, extensionData?: ExtensionData): Promise<EPResponse | null>;
export declare function eventServer<T extends Request>(request: T, eventData: EventData): Promise<EPResponse | null>;

@@ -11,9 +11,8 @@ "use strict";

* A function that sends an event to SitecoreCloud API with the specified type
* @param type - The required type of the event
*
* @param request - Interface with constraint for extending request
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param request - Interface with constraint for extending request
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* @returns The response object that Sitecore EP returns
*/
function eventServer(type, eventData, request, extensionData) {
function eventServer(request, eventData) {
const settings = (0, core_1.handleGetSettingsError)(core_1.getSettingsServer, consts_1.ErrorMessages.IE_0005);

@@ -23,9 +22,7 @@ const id = (0, core_1.getBrowserIdFromRequest)(request, settings.cookieSettings.cookieName);

eventData,
extensionData,
id,
sendEvent: sendEvent_1.sendEvent,
settings,
type,
}).send();
}
exports.eventServer = eventServer;
import { EPResponse } from '@sitecore-cloudsdk/core';
/**
* A function that sends a form event to SitecoreCloud API
*
* @param formId - The required form ID string

@@ -5,0 +6,0 @@ * @param interactionType - The required interaction type string. Possible values: "VIEWED", "SUBMITTED"

@@ -12,2 +12,3 @@ "use strict";

* A function that sends a form event to SitecoreCloud API
*
* @param formId - The required form ID string

@@ -23,6 +24,8 @@ * @param interactionType - The required interaction type string. Possible values: "VIEWED", "SUBMITTED"

const formEvent = new custom_event_1.CustomEvent({
eventData: {},
extensionData: {
formId,
interactionType: interactionType.toUpperCase(),
eventData: {
extensionData: {
formId,
interactionType: interactionType.toUpperCase(),
},
type: 'FORM',
},

@@ -32,3 +35,2 @@ id,

settings,
type: 'FORM',
});

@@ -35,0 +37,0 @@ formEvent.page = undefined;

@@ -7,3 +7,3 @@ import { BaseEvent } from '../base-event';

export declare class IdentityEvent extends BaseEvent {
private eventData;
private identityData;
private sendEvent;

@@ -15,2 +15,3 @@ private extensionData;

* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
*
* @param args - Unified object containing the required properties

@@ -21,3 +22,3 @@ */

* Function that validates the identifiers object, email and date attributes for CDN users
* * @param eventData - The data to be validated
* * @param identityData - The data to be validated
*/

@@ -47,3 +48,3 @@ private validateAttributes;

*/
export interface IdentityEventAttributesInput extends EventAttributesInput {
export interface IdentityData extends EventAttributesInput {
city?: string;

@@ -63,2 +64,3 @@ country?: string;

title?: string;
extensionData?: ExtensionData;
}

@@ -99,4 +101,3 @@ /**

sendEvent: SendEvent;
eventData: IdentityEventAttributesInput;
extensionData?: ExtensionData;
identityData: IdentityData;
id: string;

@@ -103,0 +104,0 @@ settings: Settings;

@@ -12,15 +12,16 @@ "use strict";

* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
*
* @param args - Unified object containing the required properties
*/
constructor(args) {
const { channel, currency, language, page } = args.eventData;
const { channel, currency, language, page, extensionData } = args.identityData;
super({ channel, currency, language, page }, args.id);
this.extensionData = {};
this.numberOfExtensionDataProperties = 0;
this.validateAttributes(args.eventData);
this.eventData = args.eventData;
this.validateAttributes(args.identityData);
this.identityData = args.identityData;
this.sendEvent = args.sendEvent;
this.settings = args.settings;
if (args.extensionData)
this.extensionData = (0, utils_1.flattenObject)({ object: args.extensionData });
if (extensionData)
this.extensionData = (0, utils_1.flattenObject)({ object: extensionData });
this.numberOfExtensionDataProperties = Object.entries(this.extensionData).length;

@@ -32,14 +33,14 @@ if (this.numberOfExtensionDataProperties > consts_1.MAX_EXT_ATTRIBUTES)

* Function that validates the identifiers object, email and date attributes for CDN users
* * @param eventData - The data to be validated
* * @param identityData - The data to be validated
*/
validateAttributes(eventData) {
if (eventData.identifiers.length === 0)
validateAttributes(identityData) {
if (identityData.identifiers.length === 0)
throw new Error(consts_2.ErrorMessages.MV_0003);
if (eventData.dob !== undefined && !(0, utils_1.isShortISODateString)(eventData.dob))
if (identityData.dob !== undefined && !(0, utils_1.isShortISODateString)(identityData.dob))
throw new Error(consts_2.ErrorMessages.IV_0002);
eventData.identifiers.forEach((identifier) => {
identityData.identifiers.forEach((identifier) => {
if (identifier.expiryDate && !(0, utils_1.isShortISODateString)(identifier.expiryDate))
throw new Error(consts_2.ErrorMessages.IV_0004);
});
if (eventData.email && !(0, utils_1.isValidEmail)(eventData.email))
if (identityData.email && !(0, utils_1.isValidEmail)(identityData.email))
throw new Error(consts_2.ErrorMessages.IV_0003);

@@ -53,9 +54,9 @@ }

const identityPayload = {
city: this.eventData.city,
country: this.eventData.country,
dob: this.eventData.dob,
email: this.eventData.email,
firstname: this.eventData.firstName,
gender: this.eventData.gender,
identifiers: this.eventData.identifiers.map((value) => {
city: this.identityData.city,
country: this.identityData.country,
dob: this.identityData.dob,
email: this.identityData.email,
firstname: this.identityData.firstName,
gender: this.identityData.gender,
identifiers: this.identityData.identifiers.map((value) => {
return {

@@ -68,10 +69,10 @@ // eslint-disable-next-line @typescript-eslint/naming-convention

}),
lastname: this.eventData.lastName,
mobile: this.eventData.mobile,
phone: this.eventData.phone,
lastname: this.identityData.lastName,
mobile: this.identityData.mobile,
phone: this.identityData.phone,
// eslint-disable-next-line @typescript-eslint/naming-convention
postal_code: this.eventData.postalCode,
state: this.eventData.state,
street: this.eventData.street,
title: this.eventData.title,
postal_code: this.identityData.postalCode,
state: this.identityData.state,
street: this.identityData.street,
title: this.identityData.title,
type: 'IDENTITY',

@@ -78,0 +79,0 @@ };

@@ -1,11 +0,9 @@

import { ExtensionData } from '../common-interfaces';
import { EPResponse } from '@sitecore-cloudsdk/core';
import { IdentityEventAttributesInput } from './identity-event';
import { IdentityData } from './identity-event';
/**
* A function that sends an IDENTITY event to SitecoreCloud API
*
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent 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 identity(eventData: IdentityEventAttributesInput, extensionData?: ExtensionData): Promise<EPResponse | null>;
export declare function identity(identityData: IdentityData): Promise<EPResponse | null>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.identity = 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");

@@ -11,8 +12,7 @@ const identity_event_1 = require("./identity-event");

* A function that sends an IDENTITY event to SitecoreCloud API
*
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent 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
*/
async function identity(eventData, extensionData) {
async function identity(identityData) {
await (0, initializer_1.awaitInit)();

@@ -22,5 +22,4 @@ const settings = (0, core_1.handleGetSettingsError)(core_1.getSettings, consts_1.ErrorMessages.IE_0004);

return new identity_event_1.IdentityEvent({
eventData,
extensionData,
id,
identityData,
sendEvent: sendEvent_1.sendEvent,

@@ -27,0 +26,0 @@ settings,

@@ -1,13 +0,11 @@

import { ExtensionData } from '../common-interfaces';
import { Request } from '@sitecore-cloudsdk/utils';
import { EPResponse } from '@sitecore-cloudsdk/core';
import { IdentityEventAttributesInput } from './identity-event';
import { IdentityData } from './identity-event';
/**
* A function that sends an IDENTITY event to SitecoreCloud API
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
*
* @param request - Interface with constraint for extending request
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* This object will be flattened and sent in the ext object of the payload
* @param identityData - The required/optional attributes in order to be send to SitecoreCloud API
* @returns The response object that Sitecore EP returns
*/
export declare function identityServer(eventData: IdentityEventAttributesInput, request: Request, extensionData?: ExtensionData): Promise<EPResponse | null>;
export declare function identityServer(request: Request, identityData: IdentityData): Promise<EPResponse | null>;

@@ -11,15 +11,13 @@ "use strict";

* A function that sends an IDENTITY event to SitecoreCloud API
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
*
* @param request - Interface with constraint for extending request
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* This object will be flattened and sent in the ext object of the payload
* @param identityData - The required/optional attributes in order to be send to SitecoreCloud API
* @returns The response object that Sitecore EP returns
*/
function identityServer(eventData, request, extensionData) {
function identityServer(request, identityData) {
const settings = (0, core_1.handleGetSettingsError)(core_1.getSettingsServer, consts_1.ErrorMessages.IE_0005);
const id = (0, core_1.getBrowserIdFromRequest)(request, settings.cookieSettings.cookieName);
return new identity_event_1.IdentityEvent({
eventData,
extensionData,
id,
identityData,
sendEvent: sendEvent_1.sendEvent,

@@ -26,0 +24,0 @@ settings: settings,

export { BaseEvent } from './base-event';
export type { BasePayload } from './base-event';
export { PageViewEvent } from './page-view/page-view-event';
export type { PageViewEventInput, PageViewEventPayload } from './page-view/page-view-event';
export type { PageViewData, PageViewEventPayload } from './page-view/page-view-event';
export { CustomEvent } from './custom-event/custom-event';
export type { CustomEventInput, CustomEventPayload, CustomEventArguments } from './custom-event/custom-event';
export type { EventData, CustomEventPayload, CustomEventArguments } from './custom-event/custom-event';
export { IdentityEvent } from './identity/identity-event';
export type { IdentityEventAttributesInput, IdentityEventPayload } from './identity/identity-event';
export type { IdentityData, IdentityEventPayload } from './identity/identity-event';
export type { ExtensionData } from './common-interfaces';
import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
import { FlattenedObject, NestedObject } from '@sitecore-cloudsdk/utils';
import { BaseEvent } from '../base-event';
import { EventAttributesInput } from '../common-interfaces';
import { EventAttributesInput, ExtensionData } from '../common-interfaces';
import { SendEvent } from '../send-event/sendEvent';

@@ -9,3 +9,3 @@ export declare class PageViewEvent extends BaseEvent {

private sendEvent;
private eventData;
private pageViewData;
private extensionData;

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

sendEvent: SendEvent;
eventData: PageViewEventInput;
pageViewData: PageViewData;
id: string;

@@ -64,6 +64,7 @@ settings: Settings;

*/
export interface PageViewEventInput extends EventAttributesInput {
export interface PageViewData extends EventAttributesInput {
pageVariantId?: string;
referrer?: string;
includeUTMParameters?: boolean;
extensionData?: ExtensionData;
}

@@ -70,0 +71,0 @@ /**

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

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

@@ -23,8 +23,8 @@ channel,

this.extensionData = {};
this.eventData = args.eventData;
this.pageViewData = args.pageViewData;
this.sendEvent = args.sendEvent;
this.settings = args.settings;
this.urlSearchParams = new URLSearchParams(decodeURI(args.searchParams));
if (args.extensionData)
this.extensionData = (0, utils_1.flattenObject)({ object: args.extensionData });
if (extensionData)
this.extensionData = (0, utils_1.flattenObject)({ object: extensionData });
const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;

@@ -34,3 +34,3 @@ if (numberOfExtensionDataProperties > consts_1.MAX_EXT_ATTRIBUTES)

this.includeUTMParameters =
args.eventData.includeUTMParameters === undefined ? true : args.eventData.includeUTMParameters;
args.pageViewData.includeUTMParameters === undefined ? true : args.pageViewData.includeUTMParameters;
}

@@ -42,5 +42,5 @@ /**

*/
getPageVariantId(pageVariantIdFromEventData, pageVariantIdFromExt) {
if (pageVariantIdFromEventData)
return pageVariantIdFromEventData;
getPageVariantId(pageVariantIdFromPageViewData, pageVariantIdFromExt) {
if (pageVariantIdFromPageViewData)
return pageVariantIdFromPageViewData;
const pageVariantIdFromURL = this.urlSearchParams.get('variantid');

@@ -59,4 +59,4 @@ if (pageVariantIdFromURL)

getReferrer() {
if (this.eventData.referrer)
return this.eventData.referrer;
if (this.pageViewData.referrer)
return this.pageViewData.referrer;
if (typeof window === 'undefined')

@@ -77,3 +77,3 @@ return null;

};
const pageVariantId = this.getPageVariantId(this.eventData.pageVariantId, this.extensionData['pageVariantId']);
const pageVariantId = this.getPageVariantId(this.pageViewData.pageVariantId, this.extensionData['pageVariantId']);
if (pageVariantId !== null)

@@ -80,0 +80,0 @@ viewPayload.ext = { ...viewPayload.ext, pageVariantId };

import { EPResponse } from '@sitecore-cloudsdk/core';
import { NestedObject, Request } from '@sitecore-cloudsdk/utils';
import { PageViewEventInput } from './page-view-event';
import { Request } from '@sitecore-cloudsdk/utils';
import { PageViewData } from './page-view-event';
/**
* A function that sends a VIEW event to SitecoreCloud API
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
*
* @param request - Interface with constraint for extending request
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* This object will be flattened and sent in the ext object of the payload
* @param pageViewData - The required/optional attributes in order to be send to SitecoreCloud API
* @returns The response object that Sitecore EP returns
*/
export declare function pageViewServer<T extends Request>(eventData: PageViewEventInput, request: T, extensionData?: NestedObject): Promise<EPResponse | null>;
export declare function pageViewServer<T extends Request>(request: T, pageViewData: PageViewData): Promise<EPResponse | null>;

@@ -11,9 +11,8 @@ "use strict";

* A function that sends a VIEW event to SitecoreCloud API
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
*
* @param request - Interface with constraint for extending request
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* This object will be flattened and sent in the ext object of the payload
* @param pageViewData - The required/optional attributes in order to be send to SitecoreCloud API
* @returns The response object that Sitecore EP returns
*/
function pageViewServer(eventData, request, extensionData) {
function pageViewServer(request, pageViewData) {
const settings = (0, core_1.handleGetSettingsError)(core_1.getSettingsServer, consts_1.ErrorMessages.IE_0005);

@@ -24,5 +23,4 @@ const id = (0, core_1.getBrowserIdFromRequest)(request, settings.cookieSettings.cookieName);

return new page_view_event_1.PageViewEvent({
eventData,
extensionData,
id,
pageViewData,
searchParams: requestUrl.search,

@@ -29,0 +27,0 @@ sendEvent: sendEvent_1.sendEvent,

import { EPResponse } from '@sitecore-cloudsdk/core';
import { NestedObject } from '@sitecore-cloudsdk/utils';
import { PageViewEventInput } from './page-view-event';
import { PageViewData } from './page-view-event';
/**
* A function that sends a VIEW event to SitecoreCloud API
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
*
* @param pageViewData - The required/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(eventData: PageViewEventInput, extensionData?: NestedObject): Promise<EPResponse | null>;
export declare function pageView(pageViewData: PageViewData): Promise<EPResponse | null>;

@@ -12,8 +12,8 @@ "use strict";

* A function that sends a VIEW event to SitecoreCloud API
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
*
* @param pageViewData - The required/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
*/
async function pageView(eventData, extensionData) {
async function pageView(pageViewData) {
await (0, initializer_1.awaitInit)();

@@ -23,5 +23,4 @@ const settings = (0, core_1.handleGetSettingsError)(core_1.getSettings, consts_1.ErrorMessages.IE_0004);

return new page_view_event_1.PageViewEvent({
eventData,
extensionData,
id,
pageViewData,
searchParams: window.location.search,

@@ -28,0 +27,0 @@ sendEvent: sendEvent_1.sendEvent,

@@ -1,9 +0,7 @@

import { CustomEventInput, ExtensionData } from '../events';
import { EventData } from '../events';
/**
* A function that adds event to the queue
* @param type - The required type of the event
*
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* This object will be flattened and sent in the ext object of the payload
*/
export declare function addToEventQueue(type: string, eventData: CustomEventInput, extensionData?: ExtensionData): Promise<void>;
export declare function addToEventQueue(eventData: EventData): Promise<void>;

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

* A function that adds event to the queue
* @param type - The required type of the event
*
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* This object will be flattened and sent in the ext object of the payload
*/
async function addToEventQueue(type, eventData, extensionData) {
async function addToEventQueue(eventData) {
await (0, initializer_1.awaitInit)();

@@ -23,6 +21,4 @@ const settings = (0, core_1.handleGetSettingsError)(core_1.getSettings, consts_1.ErrorMessages.IE_0004);

eventData,
extensionData,
id,
settings,
type,
};

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

@@ -33,4 +33,4 @@ import { CustomEventArguments } from '../events';

}
export type QueueEventPayload = Pick<CustomEventArguments, 'eventData' | 'extensionData' | 'type' | 'settings' | 'id'>;
export type QueueEventPayload = Pick<CustomEventArguments, 'eventData' | 'settings' | 'id'>;
export declare const eventQueue: EventQueue;
export {};

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

eventData: queueEventPayload.eventData,
extensionData: queueEventPayload.extensionData,
id: queueEventPayload.id,
sendEvent: sendEvent_1.sendEvent,
settings: queueEventPayload.settings,
type: queueEventPayload.type,
}).send();

@@ -59,0 +57,0 @@ }

@@ -1,9 +0,9 @@

import { SettingsParamsBrowser } from '@sitecore-cloudsdk/core';
import { BrowserSettings } from '@sitecore-cloudsdk/core';
export declare let initPromise: Promise<void> | null;
/**
* Initiates the Events library using the global settings added by the developer
* @param settingsInput - Global settings added by the developer
* @param settings - Global settings added by the developer
* @returns A promise that resolves with an object that handles the library functionality
*/
export declare function init(settingsInput: SettingsParamsBrowser): Promise<void>;
export declare function init(settings: BrowserSettings): Promise<void>;
/**

@@ -10,0 +10,0 @@ * A function that handles the async browser init logic. Throws an error or awaits the promise.

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

* Initiates the Events library using the global settings added by the developer
* @param settingsInput - Global settings added by the developer
* @param settings - Global settings added by the developer
* @returns A promise that resolves with an object that handles the library functionality
*/
async function init(settingsInput) {
async function init(settings) {
if (typeof window === 'undefined')
throw new Error(consts_1.ErrorMessages.IE_0001);
try {
exports.initPromise = (0, core_1.initCore)(settingsInput);
exports.initPromise = (0, core_1.initCore)(settings);
await exports.initPromise;

@@ -20,0 +20,0 @@ (0, core_1.debug)(consts_1.EVENTS_NAMESPACE)('eventsClient library initialized');

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

import { SettingsParamsServer } from '@sitecore-cloudsdk/core';
import { ServerSettings } from '@sitecore-cloudsdk/core';
import { HttpResponse, MiddlewareNextResponse, Request } from '@sitecore-cloudsdk/utils';
/**
* Initiates the server Events library using the global settings added by the developer
* @param request - The request object, either a Middleware Request or an HTTP Request
* @param response - The response object, either a Middleware Next Response or an HTTP Response
* @param settings - Global settings added by the developer
* @returns A promise that resolves with an object that handles the library functionality
*/
export declare function initServer<Response extends MiddlewareNextResponse | HttpResponse>(settingsInput: SettingsParamsServer, request: Request, response: Response): Promise<void>;
export declare function initServer<Response extends MiddlewareNextResponse | HttpResponse>(request: Request, response: Response, settings: ServerSettings): Promise<void>;

@@ -9,8 +9,10 @@ "use strict";

* Initiates the server Events library using the global settings added by the developer
* @param request - The request object, either a Middleware Request or an HTTP Request
* @param response - The response object, either a Middleware Next Response or an HTTP Response
* @param settings - Global settings added by the developer
* @returns A promise that resolves with an object that handles the library functionality
*/
async function initServer(settingsInput, request, response) {
async function initServer(request, response, settings) {
try {
await (0, core_1.initCoreServer)(settingsInput, request, response);
await (0, core_1.initCoreServer)(settings, request, response);
(0, core_1.debug)(consts_1.EVENTS_NAMESPACE)('eventsServer library initialized');

@@ -17,0 +19,0 @@ }

@@ -6,2 +6,2 @@ export { initServer as init } from './lib/initializer/server/initializer';

export { LIBRARY_VERSION, EVENTS_NAMESPACE } from './lib/consts';
export type { PageViewEventInput, CustomEventInput, IdentityEventAttributesInput } from './lib/events';
export type { PageViewData, EventData, IdentityData } from './lib/events';
{
"name": "@sitecore-cloudsdk/events",
"version": "0.2.4",
"version": "0.3.0",
"license": "Apache-2.0",
"homepage": "https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-cloud-sdk.html",
"homepage": "https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html",
"exports": {

@@ -19,4 +19,4 @@ "./server": {

"dependencies": {
"@sitecore-cloudsdk/core": "^0.2.4",
"@sitecore-cloudsdk/utils": "^0.2.4"
"@sitecore-cloudsdk/core": "^0.3.0",
"@sitecore-cloudsdk/utils": "^0.3.0"
},

@@ -39,5 +39,4 @@ "scripts": {

"engines": {
"node": ">=18",
"npm": ">=9"
"node": ">=18"
}
}
export { getBrowserId } from '@sitecore-cloudsdk/core';
export { init } from './lib/initializer/browser/initializer';
export type { PageViewEventInput, CustomEventInput, IdentityEventAttributesInput } from './lib/events';
export type { PageViewData, EventData, IdentityData } from './lib/events';
export { addToEventQueue } from './lib/eventStorage/addToEventQueue';

@@ -5,0 +5,0 @@ export { processEventQueue } from './lib/eventStorage/processEventQueue';

@@ -12,5 +12,5 @@ /**

IV_0004 = "[IV-0004] Incorrect value for \"expiryDate\". Format the value according to ISO 8601.",
IV_0005 = "[IV-0005] This event supports maximum 50 attributes. Reduce the number of attributes.",
IV_0005 = "[IV-0005] \"extensionData\" supports maximum 50 attributes. Reduce the number of attributes.",
MV_0003 = "[MV-0003] \"identifiers\" is required."
}
export declare const EVENTS_NAMESPACE = "sitecore-cloudsdk:events";

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

ErrorMessages["IV_0004"] = "[IV-0004] Incorrect value for \"expiryDate\". Format the value according to ISO 8601.";
ErrorMessages["IV_0005"] = "[IV-0005] This event supports maximum 50 attributes. Reduce the number of attributes.";
ErrorMessages["IV_0005"] = "[IV-0005] \"extensionData\" supports maximum 50 attributes. Reduce the number of attributes.";
ErrorMessages["MV_0003"] = "[MV-0003] \"identifiers\" is required.";
})(ErrorMessages || (ErrorMessages = {}));
export const EVENTS_NAMESPACE = 'sitecore-cloudsdk:events';

@@ -33,3 +33,3 @@ import { EventAttributesInput } from './common-interfaces';

}
type BaseEventData = Partial<EventAttributesInput>;
type BaseEventData = EventAttributesInput;
export {};
import { NestedObject } from '@sitecore-cloudsdk/utils';
/**
* Event data received as input to be sent to Sitecore EP
*/
interface MandatoryInput {
channel: string;
currency: string;
}
type MandatoryEventInput = MandatoryInput;
/**
* Event data that is sent to Sitecore EP
*/
interface InferrableInput {
/**
* To be restored back to MandatoryEventInput Interface
* as mandatory input parameter in version 1.0.0
*/
export interface EventAttributesInput {
language?: string;
page?: string;
channel?: string;
currency?: string;
}
type InferrableEventInput = InferrableInput;
/**
* Interface to hold the base event attributes
*/
export interface EventAttributesInput extends MandatoryEventInput, InferrableEventInput {
}
/**
* Type of the extension data that the developer can pass to events
*/
export type ExtensionData = NestedObject;
export {};
import { BaseEvent } from '../base-event';
import { EventAttributesInput } from '../common-interfaces';
import { EventAttributesInput, ExtensionData } from '../common-interfaces';
import { SendEvent } from '../send-event/sendEvent';

@@ -27,7 +27,5 @@ import { EPResponse, Settings } from '@sitecore-cloudsdk/core';

sendEvent: SendEvent;
eventData: CustomEventData;
eventData: EventData;
id: string;
extensionData?: NestedObject;
settings: Settings;
type: string;
}

@@ -45,9 +43,5 @@ /**

*/
export interface CustomEventInput extends EventAttributesInput, NestedObject {
export interface EventData extends EventAttributesInput, NestedObject {
type: string;
extensionData?: ExtensionData;
}
/**
* Internal interface with the required/optional attributes in order to send a custom event to SitecoreCloud API
*/
interface CustomEventData extends Partial<EventAttributesInput>, NestedObject {
}
export {};

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

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

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

this.customEventPayload = {
type: args.type,
type,
...rest,
};
if (args.extensionData)
this.extensionData = flattenObject({ object: args.extensionData });
if (extensionData)
this.extensionData = flattenObject({ object: extensionData });
const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;

@@ -26,0 +26,0 @@ if (numberOfExtensionDataProperties > MAX_EXT_ATTRIBUTES)

import { EPResponse } from '@sitecore-cloudsdk/core';
import { ExtensionData } from '../common-interfaces';
import { CustomEventInput } from './custom-event';
import { EventData } from './custom-event';
/**
* A function that sends an event to SitecoreCloud API with the specified type
* @param type - The required type of the event
*
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent 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 event(type: string, eventData: CustomEventInput, extensionData?: ExtensionData): Promise<EPResponse | null>;
export declare function event(eventData: EventData): Promise<EPResponse | null>;

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

* A function that sends an event to SitecoreCloud API with the specified type
* @param type - The required type of the event
*
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent 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 async function event(type, eventData, extensionData) {
export async function event(eventData) {
await awaitInit();

@@ -22,8 +20,6 @@ const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0004);

eventData,
extensionData,
id,
sendEvent,
settings,
type,
}).send();
}
import { EPResponse } from '@sitecore-cloudsdk/core';
import { ExtensionData } from '../common-interfaces';
import { CustomEventInput } from './custom-event';
import { EventData } from './custom-event';
import { Request } from '@sitecore-cloudsdk/utils';
/**
* A function that sends an event to SitecoreCloud API with the specified type
* @param type - The required type of the event
*
* @param request - Interface with constraint for extending request
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param request - Interface with constraint for extending request
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* @returns The response object that Sitecore EP returns
*/
export declare function eventServer<T extends Request>(type: string, eventData: CustomEventInput, request: T, extensionData?: ExtensionData): Promise<EPResponse | null>;
export declare function eventServer<T extends Request>(request: T, eventData: EventData): Promise<EPResponse | null>;

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

* A function that sends an event to SitecoreCloud API with the specified type
* @param type - The required type of the event
*
* @param request - Interface with constraint for extending request
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param request - Interface with constraint for extending request
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* @returns The response object that Sitecore EP returns
*/
export function eventServer(type, eventData, request, extensionData) {
export function eventServer(request, eventData) {
const settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0005);

@@ -20,8 +19,6 @@ const id = getBrowserIdFromRequest(request, settings.cookieSettings.cookieName);

eventData,
extensionData,
id,
sendEvent,
settings,
type,
}).send();
}
import { EPResponse } from '@sitecore-cloudsdk/core';
/**
* A function that sends a form event to SitecoreCloud API
*
* @param formId - The required form ID string

@@ -5,0 +6,0 @@ * @param interactionType - The required interaction type string. Possible values: "VIEWED", "SUBMITTED"

@@ -9,2 +9,3 @@ // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.

* A function that sends a form event to SitecoreCloud API
*
* @param formId - The required form ID string

@@ -20,6 +21,8 @@ * @param interactionType - The required interaction type string. Possible values: "VIEWED", "SUBMITTED"

const formEvent = new CustomEvent({
eventData: {},
extensionData: {
formId,
interactionType: interactionType.toUpperCase(),
eventData: {
extensionData: {
formId,
interactionType: interactionType.toUpperCase(),
},
type: 'FORM',
},

@@ -29,3 +32,2 @@ id,

settings,
type: 'FORM',
});

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

@@ -7,3 +7,3 @@ import { BaseEvent } from '../base-event';

export declare class IdentityEvent extends BaseEvent {
private eventData;
private identityData;
private sendEvent;

@@ -15,2 +15,3 @@ private extensionData;

* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
*
* @param args - Unified object containing the required properties

@@ -21,3 +22,3 @@ */

* Function that validates the identifiers object, email and date attributes for CDN users
* * @param eventData - The data to be validated
* * @param identityData - The data to be validated
*/

@@ -47,3 +48,3 @@ private validateAttributes;

*/
export interface IdentityEventAttributesInput extends EventAttributesInput {
export interface IdentityData extends EventAttributesInput {
city?: string;

@@ -63,2 +64,3 @@ country?: string;

title?: string;
extensionData?: ExtensionData;
}

@@ -99,4 +101,3 @@ /**

sendEvent: SendEvent;
eventData: IdentityEventAttributesInput;
extensionData?: ExtensionData;
identityData: IdentityData;
id: string;

@@ -103,0 +104,0 @@ settings: Settings;

@@ -9,15 +9,16 @@ // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.

* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
*
* @param args - Unified object containing the required properties
*/
constructor(args) {
const { channel, currency, language, page } = args.eventData;
const { channel, currency, language, page, extensionData } = args.identityData;
super({ channel, currency, language, page }, args.id);
this.extensionData = {};
this.numberOfExtensionDataProperties = 0;
this.validateAttributes(args.eventData);
this.eventData = args.eventData;
this.validateAttributes(args.identityData);
this.identityData = args.identityData;
this.sendEvent = args.sendEvent;
this.settings = args.settings;
if (args.extensionData)
this.extensionData = flattenObject({ object: args.extensionData });
if (extensionData)
this.extensionData = flattenObject({ object: extensionData });
this.numberOfExtensionDataProperties = Object.entries(this.extensionData).length;

@@ -29,14 +30,14 @@ if (this.numberOfExtensionDataProperties > MAX_EXT_ATTRIBUTES)

* Function that validates the identifiers object, email and date attributes for CDN users
* * @param eventData - The data to be validated
* * @param identityData - The data to be validated
*/
validateAttributes(eventData) {
if (eventData.identifiers.length === 0)
validateAttributes(identityData) {
if (identityData.identifiers.length === 0)
throw new Error(ErrorMessages.MV_0003);
if (eventData.dob !== undefined && !isShortISODateString(eventData.dob))
if (identityData.dob !== undefined && !isShortISODateString(identityData.dob))
throw new Error(ErrorMessages.IV_0002);
eventData.identifiers.forEach((identifier) => {
identityData.identifiers.forEach((identifier) => {
if (identifier.expiryDate && !isShortISODateString(identifier.expiryDate))
throw new Error(ErrorMessages.IV_0004);
});
if (eventData.email && !isValidEmail(eventData.email))
if (identityData.email && !isValidEmail(identityData.email))
throw new Error(ErrorMessages.IV_0003);

@@ -50,9 +51,9 @@ }

const identityPayload = {
city: this.eventData.city,
country: this.eventData.country,
dob: this.eventData.dob,
email: this.eventData.email,
firstname: this.eventData.firstName,
gender: this.eventData.gender,
identifiers: this.eventData.identifiers.map((value) => {
city: this.identityData.city,
country: this.identityData.country,
dob: this.identityData.dob,
email: this.identityData.email,
firstname: this.identityData.firstName,
gender: this.identityData.gender,
identifiers: this.identityData.identifiers.map((value) => {
return {

@@ -65,10 +66,10 @@ // eslint-disable-next-line @typescript-eslint/naming-convention

}),
lastname: this.eventData.lastName,
mobile: this.eventData.mobile,
phone: this.eventData.phone,
lastname: this.identityData.lastName,
mobile: this.identityData.mobile,
phone: this.identityData.phone,
// eslint-disable-next-line @typescript-eslint/naming-convention
postal_code: this.eventData.postalCode,
state: this.eventData.state,
street: this.eventData.street,
title: this.eventData.title,
postal_code: this.identityData.postalCode,
state: this.identityData.state,
street: this.identityData.street,
title: this.identityData.title,
type: 'IDENTITY',

@@ -75,0 +76,0 @@ };

@@ -1,11 +0,9 @@

import { ExtensionData } from '../common-interfaces';
import { EPResponse } from '@sitecore-cloudsdk/core';
import { IdentityEventAttributesInput } from './identity-event';
import { IdentityData } from './identity-event';
/**
* A function that sends an IDENTITY event to SitecoreCloud API
*
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent 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 identity(eventData: IdentityEventAttributesInput, extensionData?: ExtensionData): Promise<EPResponse | null>;
export declare function identity(identityData: IdentityData): Promise<EPResponse | null>;

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

// © 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';

@@ -8,8 +9,7 @@ import { IdentityEvent } from './identity-event';

* A function that sends an IDENTITY event to SitecoreCloud API
*
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent 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 async function identity(eventData, extensionData) {
export async function identity(identityData) {
await awaitInit();

@@ -19,5 +19,4 @@ const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0004);

return new IdentityEvent({
eventData,
extensionData,
id,
identityData,
sendEvent,

@@ -24,0 +23,0 @@ settings,

@@ -1,13 +0,11 @@

import { ExtensionData } from '../common-interfaces';
import { Request } from '@sitecore-cloudsdk/utils';
import { EPResponse } from '@sitecore-cloudsdk/core';
import { IdentityEventAttributesInput } from './identity-event';
import { IdentityData } from './identity-event';
/**
* A function that sends an IDENTITY event to SitecoreCloud API
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
*
* @param request - Interface with constraint for extending request
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* This object will be flattened and sent in the ext object of the payload
* @param identityData - The required/optional attributes in order to be send to SitecoreCloud API
* @returns The response object that Sitecore EP returns
*/
export declare function identityServer(eventData: IdentityEventAttributesInput, request: Request, extensionData?: ExtensionData): Promise<EPResponse | null>;
export declare function identityServer(request: Request, identityData: IdentityData): Promise<EPResponse | null>;

@@ -8,15 +8,13 @@ // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.

* A function that sends an IDENTITY event to SitecoreCloud API
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
*
* @param request - Interface with constraint for extending request
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* This object will be flattened and sent in the ext object of the payload
* @param identityData - The required/optional attributes in order to be send to SitecoreCloud API
* @returns The response object that Sitecore EP returns
*/
export function identityServer(eventData, request, extensionData) {
export function identityServer(request, identityData) {
const settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0005);
const id = getBrowserIdFromRequest(request, settings.cookieSettings.cookieName);
return new IdentityEvent({
eventData,
extensionData,
id,
identityData,
sendEvent,

@@ -23,0 +21,0 @@ settings: settings,

export { BaseEvent } from './base-event';
export type { BasePayload } from './base-event';
export { PageViewEvent } from './page-view/page-view-event';
export type { PageViewEventInput, PageViewEventPayload } from './page-view/page-view-event';
export type { PageViewData, PageViewEventPayload } from './page-view/page-view-event';
export { CustomEvent } from './custom-event/custom-event';
export type { CustomEventInput, CustomEventPayload, CustomEventArguments } from './custom-event/custom-event';
export type { EventData, CustomEventPayload, CustomEventArguments } from './custom-event/custom-event';
export { IdentityEvent } from './identity/identity-event';
export type { IdentityEventAttributesInput, IdentityEventPayload } from './identity/identity-event';
export type { IdentityData, IdentityEventPayload } from './identity/identity-event';
export type { ExtensionData } from './common-interfaces';
import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
import { FlattenedObject, NestedObject } from '@sitecore-cloudsdk/utils';
import { BaseEvent } from '../base-event';
import { EventAttributesInput } from '../common-interfaces';
import { EventAttributesInput, ExtensionData } from '../common-interfaces';
import { SendEvent } from '../send-event/sendEvent';

@@ -9,3 +9,3 @@ export declare class PageViewEvent extends BaseEvent {

private sendEvent;
private eventData;
private pageViewData;
private extensionData;

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

sendEvent: SendEvent;
eventData: PageViewEventInput;
pageViewData: PageViewData;
id: string;

@@ -64,6 +64,7 @@ settings: Settings;

*/
export interface PageViewEventInput extends EventAttributesInput {
export interface PageViewData extends EventAttributesInput {
pageVariantId?: string;
referrer?: string;
includeUTMParameters?: boolean;
extensionData?: ExtensionData;
}

@@ -70,0 +71,0 @@ /**

@@ -11,3 +11,3 @@ import { flattenObject } from '@sitecore-cloudsdk/utils';

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

@@ -20,8 +20,8 @@ channel,

this.extensionData = {};
this.eventData = args.eventData;
this.pageViewData = args.pageViewData;
this.sendEvent = args.sendEvent;
this.settings = args.settings;
this.urlSearchParams = new URLSearchParams(decodeURI(args.searchParams));
if (args.extensionData)
this.extensionData = flattenObject({ object: args.extensionData });
if (extensionData)
this.extensionData = flattenObject({ object: extensionData });
const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;

@@ -31,3 +31,3 @@ if (numberOfExtensionDataProperties > MAX_EXT_ATTRIBUTES)

this.includeUTMParameters =
args.eventData.includeUTMParameters === undefined ? true : args.eventData.includeUTMParameters;
args.pageViewData.includeUTMParameters === undefined ? true : args.pageViewData.includeUTMParameters;
}

@@ -39,5 +39,5 @@ /**

*/
getPageVariantId(pageVariantIdFromEventData, pageVariantIdFromExt) {
if (pageVariantIdFromEventData)
return pageVariantIdFromEventData;
getPageVariantId(pageVariantIdFromPageViewData, pageVariantIdFromExt) {
if (pageVariantIdFromPageViewData)
return pageVariantIdFromPageViewData;
const pageVariantIdFromURL = this.urlSearchParams.get('variantid');

@@ -56,4 +56,4 @@ if (pageVariantIdFromURL)

getReferrer() {
if (this.eventData.referrer)
return this.eventData.referrer;
if (this.pageViewData.referrer)
return this.pageViewData.referrer;
if (typeof window === 'undefined')

@@ -74,3 +74,3 @@ return null;

};
const pageVariantId = this.getPageVariantId(this.eventData.pageVariantId, this.extensionData['pageVariantId']);
const pageVariantId = this.getPageVariantId(this.pageViewData.pageVariantId, this.extensionData['pageVariantId']);
if (pageVariantId !== null)

@@ -77,0 +77,0 @@ viewPayload.ext = { ...viewPayload.ext, pageVariantId };

import { EPResponse } from '@sitecore-cloudsdk/core';
import { NestedObject, Request } from '@sitecore-cloudsdk/utils';
import { PageViewEventInput } from './page-view-event';
import { Request } from '@sitecore-cloudsdk/utils';
import { PageViewData } from './page-view-event';
/**
* A function that sends a VIEW event to SitecoreCloud API
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
*
* @param request - Interface with constraint for extending request
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* This object will be flattened and sent in the ext object of the payload
* @param pageViewData - The required/optional attributes in order to be send to SitecoreCloud API
* @returns The response object that Sitecore EP returns
*/
export declare function pageViewServer<T extends Request>(eventData: PageViewEventInput, request: T, extensionData?: NestedObject): Promise<EPResponse | null>;
export declare function pageViewServer<T extends Request>(request: T, pageViewData: PageViewData): Promise<EPResponse | null>;

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

* A function that sends a VIEW event to SitecoreCloud API
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
*
* @param request - Interface with constraint for extending request
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* This object will be flattened and sent in the ext object of the payload
* @param pageViewData - The required/optional attributes in order to be send to SitecoreCloud API
* @returns The response object that Sitecore EP returns
*/
export function pageViewServer(eventData, request, extensionData) {
export function pageViewServer(request, pageViewData) {
const settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0005);

@@ -21,5 +20,4 @@ const id = getBrowserIdFromRequest(request, settings.cookieSettings.cookieName);

return new PageViewEvent({
eventData,
extensionData,
id,
pageViewData,
searchParams: requestUrl.search,

@@ -26,0 +24,0 @@ sendEvent,

import { EPResponse } from '@sitecore-cloudsdk/core';
import { NestedObject } from '@sitecore-cloudsdk/utils';
import { PageViewEventInput } from './page-view-event';
import { PageViewData } from './page-view-event';
/**
* A function that sends a VIEW event to SitecoreCloud API
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
*
* @param pageViewData - The required/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(eventData: PageViewEventInput, extensionData?: NestedObject): Promise<EPResponse | null>;
export declare function pageView(pageViewData: PageViewData): Promise<EPResponse | null>;

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

* A function that sends a VIEW event to SitecoreCloud API
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
*
* @param pageViewData - The required/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 async function pageView(eventData, extensionData) {
export async function pageView(pageViewData) {
await awaitInit();

@@ -20,5 +20,4 @@ const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0004);

return new PageViewEvent({
eventData,
extensionData,
id,
pageViewData,
searchParams: window.location.search,

@@ -25,0 +24,0 @@ sendEvent,

@@ -1,9 +0,7 @@

import { CustomEventInput, ExtensionData } from '../events';
import { EventData } from '../events';
/**
* A function that adds event to the queue
* @param type - The required type of the event
*
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* This object will be flattened and sent in the ext object of the payload
*/
export declare function addToEventQueue(type: string, eventData: CustomEventInput, extensionData?: ExtensionData): Promise<void>;
export declare function addToEventQueue(eventData: EventData): Promise<void>;

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

* A function that adds event to the queue
* @param type - The required type of the event
*
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
* This object will be flattened and sent in the ext object of the payload
*/
export async function addToEventQueue(type, eventData, extensionData) {
export async function addToEventQueue(eventData) {
await awaitInit();

@@ -20,8 +18,6 @@ const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0004);

eventData,
extensionData,
id,
settings,
type,
};
eventQueue.enqueueEvent(queueEventPayload);
}

@@ -33,4 +33,4 @@ import { CustomEventArguments } from '../events';

}
export type QueueEventPayload = Pick<CustomEventArguments, 'eventData' | 'extensionData' | 'type' | 'settings' | 'id'>;
export type QueueEventPayload = Pick<CustomEventArguments, 'eventData' | 'settings' | 'id'>;
export declare const eventQueue: EventQueue;
export {};

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

eventData: queueEventPayload.eventData,
extensionData: queueEventPayload.extensionData,
id: queueEventPayload.id,
sendEvent,
settings: queueEventPayload.settings,
type: queueEventPayload.type,
}).send();

@@ -56,0 +54,0 @@ }

@@ -1,9 +0,9 @@

import { SettingsParamsBrowser } from '@sitecore-cloudsdk/core';
import { BrowserSettings } from '@sitecore-cloudsdk/core';
export declare let initPromise: Promise<void> | null;
/**
* Initiates the Events library using the global settings added by the developer
* @param settingsInput - Global settings added by the developer
* @param settings - Global settings added by the developer
* @returns A promise that resolves with an object that handles the library functionality
*/
export declare function init(settingsInput: SettingsParamsBrowser): Promise<void>;
export declare function init(settings: BrowserSettings): Promise<void>;
/**

@@ -10,0 +10,0 @@ * A function that handles the async browser init logic. Throws an error or awaits the promise.

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

* Initiates the Events library using the global settings added by the developer
* @param settingsInput - Global settings added by the developer
* @param settings - Global settings added by the developer
* @returns A promise that resolves with an object that handles the library functionality
*/
export async function init(settingsInput) {
export async function init(settings) {
if (typeof window === 'undefined')
throw new Error(ErrorMessages.IE_0001);
try {
initPromise = initCore(settingsInput);
initPromise = initCore(settings);
await initPromise;

@@ -17,0 +17,0 @@ debug(EVENTS_NAMESPACE)('eventsClient library initialized');

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

import { SettingsParamsServer } from '@sitecore-cloudsdk/core';
import { ServerSettings } from '@sitecore-cloudsdk/core';
import { HttpResponse, MiddlewareNextResponse, Request } from '@sitecore-cloudsdk/utils';
/**
* Initiates the server Events library using the global settings added by the developer
* @param request - The request object, either a Middleware Request or an HTTP Request
* @param response - The response object, either a Middleware Next Response or an HTTP Response
* @param settings - Global settings added by the developer
* @returns A promise that resolves with an object that handles the library functionality
*/
export declare function initServer<Response extends MiddlewareNextResponse | HttpResponse>(settingsInput: SettingsParamsServer, request: Request, response: Response): Promise<void>;
export declare function initServer<Response extends MiddlewareNextResponse | HttpResponse>(request: Request, response: Response, settings: ServerSettings): Promise<void>;

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

* Initiates the server Events library using the global settings added by the developer
* @param request - The request object, either a Middleware Request or an HTTP Request
* @param response - The response object, either a Middleware Next Response or an HTTP Response
* @param settings - Global settings added by the developer
* @returns A promise that resolves with an object that handles the library functionality
*/
export async function initServer(settingsInput, request, response) {
export async function initServer(request, response, settings) {
try {
await initCoreServer(settingsInput, request, response);
await initCoreServer(settings, request, response);
debug(EVENTS_NAMESPACE)('eventsServer library initialized');

@@ -14,0 +16,0 @@ }

@@ -6,2 +6,2 @@ export { initServer as init } from './lib/initializer/server/initializer';

export { LIBRARY_VERSION, EVENTS_NAMESPACE } from './lib/consts';
export type { PageViewEventInput, CustomEventInput, IdentityEventAttributesInput } from './lib/events';
export type { PageViewData, EventData, IdentityData } from './lib/events';
{
"name": "@sitecore-cloudsdk/events",
"version": "0.2.4",
"version": "0.3.0",
"license": "Apache-2.0",
"homepage": "https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-cloud-sdk.html",
"homepage": "https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html",
"exports": {

@@ -19,4 +19,4 @@ "./server": {

"dependencies": {
"@sitecore-cloudsdk/core": "^0.2.4",
"@sitecore-cloudsdk/utils": "^0.2.4"
"@sitecore-cloudsdk/core": "^0.3.0",
"@sitecore-cloudsdk/utils": "^0.3.0"
},

@@ -39,5 +39,4 @@ "scripts": {

"engines": {
"node": ">=18",
"npm": ">=9"
"node": ">=18"
}
}

@@ -59,13 +59,4 @@ # events

const sendPageViewEvent = async () => {
let eventData: any = {
channel: 'WEB',
currency: 'EUR',
};
await pageView();
let extensionData: any = {
customKey: 'customValue',
};
await pageView(eventData, extensionData);
console.log('Sent VIEW event.');

@@ -92,25 +83,12 @@ };

await init(
{
sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || '',
siteName: process.env.NEXT_PUBLIC_SITENAME || '',
enableServerCookie: true,
},
req,
res
);
await init(req, res, {
sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || '',
siteName: process.env.NEXT_PUBLIC_SITENAME || '',
enableServerCookie: true,
});
console.log(`Initialized "@sitecore-cloudsdk/events/server".`);
let eventData: any = {
channel: 'WEB',
currency: 'EUR',
};
const pageViewRes = await pageView(req);
let extensionData: any = {
customKey: 'customValue',
};
const pageViewRes = await pageView(eventData, req, extensionData);
console.log('Sent VIEW event.');

@@ -124,2 +102,2 @@

[Official Sitecore Cloud SDK documentation](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-cloud-sdk.html)
[Official Sitecore Cloud SDK documentation](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