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

@sitecore-cloudsdk/core

Package Overview
Dependencies
Maintainers
3
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sitecore-cloudsdk/core - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

2

dist/cjs/package.json
{
"name": "@sitecore-cloudsdk/core",
"version": "0.1.1",
"version": "0.1.2",
"license": "Apache-2.0",

@@ -5,0 +5,0 @@ "main": "dist/cjs/src/index.js",

@@ -17,3 +17,3 @@ export { createCookie } from './lib/cookie/create-cookie';

export { API_VERSION, COOKIE_NAME_PREFIX, DAILY_SECONDS, DEFAULT_COOKIE_EXPIRY_DAYS, LIBRARY_VERSION, SITECORE_EDGE_URL, } from './lib/consts';
export type { ICdpResponse, IInfer } from './lib/interfaces';
export type { ICookieSettings, ISettings, ISettingsParamsBrowser, ISettingsParamsServer, IWebExperiencesSettings, IWebPersonalizationConfig, } from './lib/settings/interfaces';
export type { EPResponse, Infer } from './lib/interfaces';
export type { CookieSettings, Settings, SettingsParamsBrowser, SettingsParamsServer } from './lib/settings/interfaces';

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

import { ISettings } from '../settings/interfaces';
import { Settings } from '../settings/interfaces';
/**
* Creates and adds the cookie to the document
* @param settings - The ICookieSettings settings object
* @param settings - The CookieSettings settings object
* @returns - browserId or undefined on error
*/
export declare function createCookie(settings: ISettings): Promise<void>;
export declare function createCookie(settings: Settings): Promise<void>;

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

* Creates and adds the cookie to the document
* @param settings - The ICookieSettings settings object
* @param settings - The CookieSettings settings object
* @returns - browserId or undefined on error

@@ -18,7 +18,5 @@ */

const { browserId } = await (0, fetch_browser_id_from_edge_proxy_1.fetchBrowserIdFromEdgeProxy)(settings.sitecoreEdgeUrl, settings.sitecoreEdgeContextId);
if (browserId) {
const attributes = (0, get_default_cookie_attributes_1.getDefaultCookieAttributes)(settings.cookieSettings.cookieExpiryDays, settings.cookieSettings.cookieDomain);
document.cookie = (0, utils_1.createCookieString)(settings.cookieSettings.cookieName, browserId, attributes);
}
const attributes = (0, get_default_cookie_attributes_1.getDefaultCookieAttributes)(settings.cookieSettings.cookieExpiryDays, settings.cookieSettings.cookieDomain);
document.cookie = (0, utils_1.createCookieString)(settings.cookieSettings.cookieName, browserId, attributes);
}
exports.createCookie = createCookie;

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

import { IMiddlewareRequest } from '@sitecore-cloudsdk/utils';
import { MiddlewareRequest } from '@sitecore-cloudsdk/utils';
/**

@@ -11,2 +11,2 @@ * Retrieves the browser ID from the provided Middleware Request by extracting the cookie value

*/
export declare function getBrowserIdFromMiddlewareRequest(request: IMiddlewareRequest, cookieName: string): string | undefined;
export declare function getBrowserIdFromMiddlewareRequest(request: MiddlewareRequest, cookieName: string): string | undefined;

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

import { TRequest } from '@sitecore-cloudsdk/utils';
import { Request } from '@sitecore-cloudsdk/utils';
/**

@@ -9,2 +9,2 @@ * Retrieves the browser ID from the provided request object ('T'), using the specified 'cookieName'.

*/
export declare function getBrowserIdFromRequest<T extends TRequest>(request: T, cookieName: string): string;
export declare function getBrowserIdFromRequest<T extends Request>(request: T, cookieName: string): string;

@@ -6,3 +6,3 @@ /**

*/
import { ICookieProperties } from '@sitecore-cloudsdk/utils';
export declare function getDefaultCookieAttributes(maxAge?: number, cookieDomain?: string): ICookieProperties;
import { CookieProperties } from '@sitecore-cloudsdk/utils';
export declare function getDefaultCookieAttributes(maxAge?: number, cookieDomain?: string): CookieProperties;

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

import type { IHttpRequest, IHttpResponse } from '@sitecore-cloudsdk/utils';
import { ISettings } from '../settings/interfaces';
import type { HttpRequest, HttpResponse } from '@sitecore-cloudsdk/utils';
import { Settings } from '../settings/interfaces';
/**

@@ -12,4 +12,4 @@ * Handles HTTP Cookie operations for setting the browser ID cookie in the request and response.

*
* @throws [IE-0003] - This exception is thrown in the case getBrowserIdFromCdp wasn't able to retrieve a browser id.
* @throws [IE-0003] - This exception is thrown in the case getBrowserIdFromEP wasn't able to retrieve a browser id.
*/
export declare function handleHttpCookie(request: IHttpRequest, response: IHttpResponse, options: ISettings, timeout?: number): Promise<void>;
export declare function handleHttpCookie(request: HttpRequest, response: HttpResponse, options: Settings, timeout?: number): Promise<void>;

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

*
* @throws [IE-0003] - This exception is thrown in the case getBrowserIdFromCdp wasn't able to retrieve a browser id.
* @throws [IE-0003] - This exception is thrown in the case getBrowserIdFromEP wasn't able to retrieve a browser id.
*/

@@ -30,8 +30,5 @@ async function handleHttpCookie(request, response, options, timeout) {

}
if (!cookieValue) {
const { browserId } = await (0, fetch_browser_id_from_edge_proxy_1.fetchBrowserIdFromEdgeProxy)(options.sitecoreEdgeUrl, options.sitecoreEdgeContextId, timeout);
if (!browserId)
throw new Error('[IE-0003] Unable to set the cookie because the browser ID could not be retrieved from the server. Try again later, or use try-catch blocks to handle this error.');
cookieValue = browserId;
}
if (!cookieValue)
cookieValue = (await (0, fetch_browser_id_from_edge_proxy_1.fetchBrowserIdFromEdgeProxy)(options.sitecoreEdgeUrl, options.sitecoreEdgeContextId, timeout))
.browserId;
const defaultCookieAttributes = (0, get_default_cookie_attributes_1.getDefaultCookieAttributes)(options.cookieSettings.cookieExpiryDays, options.cookieSettings.cookieDomain);

@@ -38,0 +35,0 @@ const cookieString = (0, utils_1.createCookieString)(cookieName, cookieValue, defaultCookieAttributes);

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

import { IMiddlewareNextResponse, IMiddlewareRequest } from '@sitecore-cloudsdk/utils';
import { ISettings } from '../settings/interfaces';
import { MiddlewareNextResponse, MiddlewareRequest } from '@sitecore-cloudsdk/utils';
import { Settings } from '../settings/interfaces';
/**

@@ -16,2 +16,2 @@ * Handles the Middleware Request and sets a cookie with the provided 'cookieName' and 'cookieValue'.

*/
export declare function handleNextJsMiddlewareCookie(request: IMiddlewareRequest, response: IMiddlewareNextResponse, options: ISettings, timeout?: number): Promise<void>;
export declare function handleNextJsMiddlewareCookie(request: MiddlewareRequest, response: MiddlewareNextResponse, options: Settings, timeout?: number): Promise<void>;

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

let cookieValue = (0, get_browser_id_from_middleware_request_1.getBrowserIdFromMiddlewareRequest)(request, cookieName);
if (!cookieValue) {
const { browserId } = await (0, fetch_browser_id_from_edge_proxy_1.fetchBrowserIdFromEdgeProxy)(options.sitecoreEdgeUrl, options.sitecoreEdgeContextId, timeout);
if (!browserId)
throw new Error('[IE-0003] Unable to set the cookie because the browser ID could not be retrieved from the server. Try again later, or use try-catch blocks to handle this error.');
cookieValue = browserId;
}
if (!cookieValue)
cookieValue = (await (0, fetch_browser_id_from_edge_proxy_1.fetchBrowserIdFromEdgeProxy)(options.sitecoreEdgeUrl, options.sitecoreEdgeContextId, timeout))
.browserId;
const defaultCookieAttributes = (0, get_default_cookie_attributes_1.getDefaultCookieAttributes)(options.cookieSettings.cookieExpiryDays, options.cookieSettings.cookieDomain);

@@ -32,0 +29,0 @@ request.cookies.set(cookieName, cookieValue, defaultCookieAttributes);

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

import { type TRequest, type IMiddlewareNextResponse, type IHttpResponse } from '@sitecore-cloudsdk/utils';
import { type Request, type MiddlewareNextResponse, type HttpResponse } from '@sitecore-cloudsdk/utils';
/**

@@ -10,2 +10,2 @@ * Handles server-side cookie operations based on the provided 'request' and 'response' objects.

*/
export declare function handleServerCookie<T extends TRequest, X extends IMiddlewareNextResponse | IHttpResponse>(request: T, response: X, timeout?: number): Promise<void>;
export declare function handleServerCookie<T extends Request, X extends MiddlewareNextResponse | HttpResponse>(request: T, response: X, timeout?: number): Promise<void>;

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

import { IProxySettings } from '../interfaces';
import { ProxySettings } from '../interfaces';
/**

@@ -9,2 +9,2 @@ * Gets the browser ID and Client Key from Sitecore Edge Proxy

*/
export declare function fetchBrowserIdFromEdgeProxy(sitecoreEdgeUrl: string, sitecoreEdgeContextId: string, timeout?: number): Promise<IProxySettings>;
export declare function fetchBrowserIdFromEdgeProxy(sitecoreEdgeUrl: string, sitecoreEdgeContextId: string, timeout?: number): Promise<ProxySettings>;

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

if (!response)
return { browserId: '' };
throw new Error('[IE-0003] Unable to set the cookie because the browser ID could not be retrieved from the server. Try again later, or use try-catch blocks to handle this error.');
const { ref: browserId } = response;

@@ -35,0 +35,0 @@ return { browserId };

/**
* A function that gets the guest ref from CDP.
* A function that gets the guest ref from EP.
* @param browserId - The browser id of the client

@@ -9,3 +9,3 @@ * @param sitecoreEdgeContextId - The sitecoreEdgeContextId

export declare function getGuestId(browserId: string, sitecoreEdgeContextId: string, sitecoreEdgeUrl: string): Promise<string>;
interface IGetGuestRefCommon {
interface GetGuestRefCommon {
status: string;

@@ -15,3 +15,3 @@ version: string;

}
export interface IGetGuestRefResponse extends IGetGuestRefCommon {
export interface GetGuestRefResponse extends GetGuestRefCommon {
ref: string;

@@ -22,3 +22,3 @@ customer: {

}
export interface IGetGuestRefResponseError extends IGetGuestRefCommon {
export interface GetGuestRefResponseError extends GetGuestRefCommon {
error_msg: string;

@@ -25,0 +25,0 @@ moreInfo: string;

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

/**
* A function that gets the guest ref from CDP.
* A function that gets the guest ref from EP.
* @param browserId - The browser id of the client

@@ -10,0 +10,0 @@ * @param sitecoreEdgeContextId - The sitecoreEdgeContextId

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

import { IHttpResponse, IMiddlewareNextResponse, TRequest } from '@sitecore-cloudsdk/utils';
import { ISettings, ISettingsParamsServer } from '../settings/interfaces';
export declare function setCoreSettings(settings: ISettings): void;
import { HttpResponse, MiddlewareNextResponse, Request } from '@sitecore-cloudsdk/utils';
import { Settings, SettingsParamsServer } from '../settings/interfaces';
export declare function setCoreSettings(settings: Settings): void;
/**

@@ -12,3 +12,3 @@ * Initializes the core settings for browser-based applications.

*/
export declare function getSettingsServer(): ISettings;
export declare function getSettingsServer(): Settings;
/**

@@ -22,2 +22,2 @@ * Initializes the core settings for browser-based applications.

*/
export declare function initCoreServer<TResponse extends IMiddlewareNextResponse | IHttpResponse>(settingsInput: ISettingsParamsServer, request: TRequest, response: TResponse): Promise<void>;
export declare function initCoreServer<Response extends MiddlewareNextResponse | HttpResponse>(settingsInput: SettingsParamsServer, request: Request, response: Response): Promise<void>;

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

if (!coreSettings) {
throw Error('[IE-0005] You must first initialize the "core" package. Run the "init" function.');
throw Error('[IE-0008] You must first initialize the "core" package. Run the "init" function.');
}

@@ -30,0 +30,0 @@ return coreSettings;

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

import { ISettings, ISettingsParamsBrowser } from '../settings/interfaces';
import { Settings, SettingsParamsBrowser } from '../settings/interfaces';
/**
* Enum representing the initialization statuses.
* - `NOT_STARTED`: The initialization process has not started.
* - `INITIALIZING`: The initialization process is in progress.
* - `DONE`: The initialization process is complete.
*/
export declare enum INIT_STATUSES {
NOT_STARTED = 0,
INITIALIZING = 1,
DONE = 2
}
export declare function setInitStatus(status: INIT_STATUSES): void;
export declare function setCoreSettings(settings: ISettings): void;
/**
* Retrieves the core settings object.

@@ -23,3 +10,3 @@ *

*/
export declare function getSettings(): ISettings;
export declare function getSettings(): Settings;
/**

@@ -33,2 +20,7 @@ * Initializes the core settings for browser-based applications.

*/
export declare function initCore(settingsInput: ISettingsParamsBrowser): Promise<void>;
export declare function initCore(settingsInput: SettingsParamsBrowser): Promise<void>;
/**
* Helper functions for tests
*/
export declare function setCoreSettings(settings: Settings): void;
export declare function setCookiePromise(promise: Promise<void>): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.initCore = exports.getSettings = exports.setCoreSettings = exports.setInitStatus = exports.INIT_STATUSES = void 0;
exports.setCookiePromise = exports.setCoreSettings = exports.initCore = exports.getSettings = void 0;
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.

@@ -8,15 +8,2 @@ const create_cookie_1 = require("../cookie/create-cookie");

/**
* Enum representing the initialization statuses.
* - `NOT_STARTED`: The initialization process has not started.
* - `INITIALIZING`: The initialization process is in progress.
* - `DONE`: The initialization process is complete.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
var INIT_STATUSES;
(function (INIT_STATUSES) {
INIT_STATUSES[INIT_STATUSES["NOT_STARTED"] = 0] = "NOT_STARTED";
INIT_STATUSES[INIT_STATUSES["INITIALIZING"] = 1] = "INITIALIZING";
INIT_STATUSES[INIT_STATUSES["DONE"] = 2] = "DONE";
})(INIT_STATUSES || (exports.INIT_STATUSES = INIT_STATUSES = {}));
/**
* Internal settings object to be used by all functions in module caching.

@@ -27,11 +14,2 @@ * It starts with a null value and is set to the proper object by the function. *

let coreSettings = null;
let initStatus = INIT_STATUSES.NOT_STARTED;
function setInitStatus(status) {
initStatus = status;
}
exports.setInitStatus = setInitStatus;
function setCoreSettings(settings) {
coreSettings = settings;
}
exports.setCoreSettings = setCoreSettings;
/**

@@ -47,3 +25,3 @@ * Retrieves the core settings object.

if (!coreSettings) {
throw Error(`[IE-0004] You must first initialize the "core" package. Run the "init" function.`);
throw Error(`[IE-0008] You must first initialize the "core" package. Run the "init" function.`);
}

@@ -53,2 +31,3 @@ return coreSettings;

exports.getSettings = getSettings;
let createCookiePromise = null;
/**

@@ -63,12 +42,19 @@ * Initializes the core settings for browser-based applications.

async function initCore(settingsInput) {
if (initStatus != INIT_STATUSES.NOT_STARTED)
return;
setInitStatus(INIT_STATUSES.INITIALIZING);
coreSettings = (0, create_settings_1.createSettings)(settingsInput);
setCoreSettings(coreSettings);
if (settingsInput.enableBrowserCookie) {
await (0, create_cookie_1.createCookie)(coreSettings);
}
setInitStatus(INIT_STATUSES.DONE);
if (coreSettings === null)
coreSettings = (0, create_settings_1.createSettings)(settingsInput);
if (settingsInput.enableBrowserCookie && createCookiePromise === null)
createCookiePromise = (0, create_cookie_1.createCookie)(coreSettings);
await createCookiePromise;
}
exports.initCore = initCore;
/**
* Helper functions for tests
*/
function setCoreSettings(settings) {
coreSettings = settings;
}
exports.setCoreSettings = setCoreSettings;
function setCookiePromise(promise) {
createCookiePromise = promise;
}
exports.setCookiePromise = setCookiePromise;
/**
* The response object that Sitecore CDP returns
* The response object that Sitecore EP returns
*/
export interface ICdpResponse {
export interface EPResponse {
ref: string;

@@ -10,3 +10,3 @@ status: string;

}
export interface IProxySettings {
export interface ProxySettings {
browserId: string;

@@ -17,5 +17,5 @@ }

*/
export interface IInfer {
export interface Infer {
language: () => string | undefined;
pageName: () => string;
}

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

import { ISettings, ISettingsParams } from './interfaces';
import { Settings, SettingsParams } from './interfaces';
/**
* Creates the global settings object, to be used by the library
* @param settingsInput - Global settings added by the developer.
* @returns an ISettings with the settings added by the developer
* @returns an Settings with the settings added by the developer
*/
export declare function createSettings(settingsInput: ISettingsParams): ISettings;
export declare function createSettings(settingsInput: SettingsParams): Settings;

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

* @param settingsInput - Global settings added by the developer.
* @returns an ISettings with the settings added by the developer
* @returns an Settings with the settings added by the developer
*/

@@ -13,0 +13,0 @@ function createSettings(settingsInput) {

/**
* Extends the global settings object with additional properties
*/
export interface ISettings extends IBasicSettings {
cookieSettings: ICookieSettings;
export interface Settings extends BasicSettings {
cookieSettings: CookieSettings;
sitecoreEdgeUrl: string;
}
export interface ISettingsParamsBrowser extends ISettingsParams {
export interface SettingsParamsBrowser extends SettingsParams {
enableBrowserCookie?: boolean;
}
export interface ISettingsParamsServer extends ISettingsParams {
export interface SettingsParamsServer extends SettingsParams {
enableServerCookie?: boolean;
}
export interface ISettingsParams extends IBasicSettings, ICookieSettingsInput {
export interface SettingsParams extends BasicSettings, CookieSettingsInput {
timeout?: number;

@@ -21,7 +21,7 @@ sitecoreEdgeUrl?: string;

*/
interface IBasicSettings {
interface BasicSettings {
sitecoreEdgeContextId: string;
siteName: string;
}
interface ICookieSettingsInput {
interface CookieSettingsInput {
cookiePath?: string;

@@ -34,3 +34,3 @@ cookieExpiryDays?: number;

*/
export interface ICookieSettings {
export interface CookieSettings {
cookieName: string;

@@ -44,23 +44,5 @@ cookieDomain?: string;

*/
export interface ICookieSettingsBrowser extends ICookieSettings {
export interface CookieSettingsBrowser extends CookieSettings {
enableBrowserCookie: boolean;
}
/**
* Properties for the Web Flow configuration
*/
export interface IWebPersonalizationConfig {
asyncScriptLoading?: boolean;
deferScriptLoading?: boolean;
baseURLOverride?: string;
}
export interface IWebExperiencesSettings {
targetURL: string;
pointOfSale: string;
client_key: string;
web_flow_config: {
async: boolean;
defer: boolean;
};
web_flow_target?: string;
}
export {};

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

import { ISettingsParams } from './interfaces';
import { SettingsParams } from './interfaces';
/**

@@ -10,2 +10,2 @@ * Validates the core settings to ensure they meet required criteria.

*/
export declare function validateSettings(settings: ISettingsParams): void;
export declare function validateSettings(settings: SettingsParams): void;
{
"name": "@sitecore-cloudsdk/core",
"version": "0.1.1",
"version": "0.1.2",
"license": "Apache-2.0",

@@ -5,0 +5,0 @@ "main": "dist/cjs/src/index.js",

@@ -17,3 +17,3 @@ export { createCookie } from './lib/cookie/create-cookie';

export { API_VERSION, COOKIE_NAME_PREFIX, DAILY_SECONDS, DEFAULT_COOKIE_EXPIRY_DAYS, LIBRARY_VERSION, SITECORE_EDGE_URL, } from './lib/consts';
export type { ICdpResponse, IInfer } from './lib/interfaces';
export type { ICookieSettings, ISettings, ISettingsParamsBrowser, ISettingsParamsServer, IWebExperiencesSettings, IWebPersonalizationConfig, } from './lib/settings/interfaces';
export type { EPResponse, Infer } from './lib/interfaces';
export type { CookieSettings, Settings, SettingsParamsBrowser, SettingsParamsServer } from './lib/settings/interfaces';

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

import { ISettings } from '../settings/interfaces';
import { Settings } from '../settings/interfaces';
/**
* Creates and adds the cookie to the document
* @param settings - The ICookieSettings settings object
* @param settings - The CookieSettings settings object
* @returns - browserId or undefined on error
*/
export declare function createCookie(settings: ISettings): Promise<void>;
export declare function createCookie(settings: Settings): Promise<void>;

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

* Creates and adds the cookie to the document
* @param settings - The ICookieSettings settings object
* @param settings - The CookieSettings settings object
* @returns - browserId or undefined on error

@@ -15,6 +15,4 @@ */

const { browserId } = await fetchBrowserIdFromEdgeProxy(settings.sitecoreEdgeUrl, settings.sitecoreEdgeContextId);
if (browserId) {
const attributes = getDefaultCookieAttributes(settings.cookieSettings.cookieExpiryDays, settings.cookieSettings.cookieDomain);
document.cookie = createCookieString(settings.cookieSettings.cookieName, browserId, attributes);
}
const attributes = getDefaultCookieAttributes(settings.cookieSettings.cookieExpiryDays, settings.cookieSettings.cookieDomain);
document.cookie = createCookieString(settings.cookieSettings.cookieName, browserId, attributes);
}

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

import { IMiddlewareRequest } from '@sitecore-cloudsdk/utils';
import { MiddlewareRequest } from '@sitecore-cloudsdk/utils';
/**

@@ -11,2 +11,2 @@ * Retrieves the browser ID from the provided Middleware Request by extracting the cookie value

*/
export declare function getBrowserIdFromMiddlewareRequest(request: IMiddlewareRequest, cookieName: string): string | undefined;
export declare function getBrowserIdFromMiddlewareRequest(request: MiddlewareRequest, cookieName: string): string | undefined;

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

import { TRequest } from '@sitecore-cloudsdk/utils';
import { Request } from '@sitecore-cloudsdk/utils';
/**

@@ -9,2 +9,2 @@ * Retrieves the browser ID from the provided request object ('T'), using the specified 'cookieName'.

*/
export declare function getBrowserIdFromRequest<T extends TRequest>(request: T, cookieName: string): string;
export declare function getBrowserIdFromRequest<T extends Request>(request: T, cookieName: string): string;

@@ -6,3 +6,3 @@ /**

*/
import { ICookieProperties } from '@sitecore-cloudsdk/utils';
export declare function getDefaultCookieAttributes(maxAge?: number, cookieDomain?: string): ICookieProperties;
import { CookieProperties } from '@sitecore-cloudsdk/utils';
export declare function getDefaultCookieAttributes(maxAge?: number, cookieDomain?: string): CookieProperties;

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

import type { IHttpRequest, IHttpResponse } from '@sitecore-cloudsdk/utils';
import { ISettings } from '../settings/interfaces';
import type { HttpRequest, HttpResponse } from '@sitecore-cloudsdk/utils';
import { Settings } from '../settings/interfaces';
/**

@@ -12,4 +12,4 @@ * Handles HTTP Cookie operations for setting the browser ID cookie in the request and response.

*
* @throws [IE-0003] - This exception is thrown in the case getBrowserIdFromCdp wasn't able to retrieve a browser id.
* @throws [IE-0003] - This exception is thrown in the case getBrowserIdFromEP wasn't able to retrieve a browser id.
*/
export declare function handleHttpCookie(request: IHttpRequest, response: IHttpResponse, options: ISettings, timeout?: number): Promise<void>;
export declare function handleHttpCookie(request: HttpRequest, response: HttpResponse, options: Settings, timeout?: number): Promise<void>;

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

*
* @throws [IE-0003] - This exception is thrown in the case getBrowserIdFromCdp wasn't able to retrieve a browser id.
* @throws [IE-0003] - This exception is thrown in the case getBrowserIdFromEP wasn't able to retrieve a browser id.
*/

@@ -27,8 +27,5 @@ export async function handleHttpCookie(request, response, options, timeout) {

}
if (!cookieValue) {
const { browserId } = await fetchBrowserIdFromEdgeProxy(options.sitecoreEdgeUrl, options.sitecoreEdgeContextId, timeout);
if (!browserId)
throw new Error('[IE-0003] Unable to set the cookie because the browser ID could not be retrieved from the server. Try again later, or use try-catch blocks to handle this error.');
cookieValue = browserId;
}
if (!cookieValue)
cookieValue = (await fetchBrowserIdFromEdgeProxy(options.sitecoreEdgeUrl, options.sitecoreEdgeContextId, timeout))
.browserId;
const defaultCookieAttributes = getDefaultCookieAttributes(options.cookieSettings.cookieExpiryDays, options.cookieSettings.cookieDomain);

@@ -35,0 +32,0 @@ const cookieString = createCookieString(cookieName, cookieValue, defaultCookieAttributes);

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

import { IMiddlewareNextResponse, IMiddlewareRequest } from '@sitecore-cloudsdk/utils';
import { ISettings } from '../settings/interfaces';
import { MiddlewareNextResponse, MiddlewareRequest } from '@sitecore-cloudsdk/utils';
import { Settings } from '../settings/interfaces';
/**

@@ -16,2 +16,2 @@ * Handles the Middleware Request and sets a cookie with the provided 'cookieName' and 'cookieValue'.

*/
export declare function handleNextJsMiddlewareCookie(request: IMiddlewareRequest, response: IMiddlewareNextResponse, options: ISettings, timeout?: number): Promise<void>;
export declare function handleNextJsMiddlewareCookie(request: MiddlewareRequest, response: MiddlewareNextResponse, options: Settings, timeout?: number): Promise<void>;

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

let cookieValue = getBrowserIdFromMiddlewareRequest(request, cookieName);
if (!cookieValue) {
const { browserId } = await fetchBrowserIdFromEdgeProxy(options.sitecoreEdgeUrl, options.sitecoreEdgeContextId, timeout);
if (!browserId)
throw new Error('[IE-0003] Unable to set the cookie because the browser ID could not be retrieved from the server. Try again later, or use try-catch blocks to handle this error.');
cookieValue = browserId;
}
if (!cookieValue)
cookieValue = (await fetchBrowserIdFromEdgeProxy(options.sitecoreEdgeUrl, options.sitecoreEdgeContextId, timeout))
.browserId;
const defaultCookieAttributes = getDefaultCookieAttributes(options.cookieSettings.cookieExpiryDays, options.cookieSettings.cookieDomain);

@@ -29,0 +26,0 @@ request.cookies.set(cookieName, cookieValue, defaultCookieAttributes);

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

import { type TRequest, type IMiddlewareNextResponse, type IHttpResponse } from '@sitecore-cloudsdk/utils';
import { type Request, type MiddlewareNextResponse, type HttpResponse } from '@sitecore-cloudsdk/utils';
/**

@@ -10,2 +10,2 @@ * Handles server-side cookie operations based on the provided 'request' and 'response' objects.

*/
export declare function handleServerCookie<T extends TRequest, X extends IMiddlewareNextResponse | IHttpResponse>(request: T, response: X, timeout?: number): Promise<void>;
export declare function handleServerCookie<T extends Request, X extends MiddlewareNextResponse | HttpResponse>(request: T, response: X, timeout?: number): Promise<void>;

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

import { IProxySettings } from '../interfaces';
import { ProxySettings } from '../interfaces';
/**

@@ -9,2 +9,2 @@ * Gets the browser ID and Client Key from Sitecore Edge Proxy

*/
export declare function fetchBrowserIdFromEdgeProxy(sitecoreEdgeUrl: string, sitecoreEdgeContextId: string, timeout?: number): Promise<IProxySettings>;
export declare function fetchBrowserIdFromEdgeProxy(sitecoreEdgeUrl: string, sitecoreEdgeContextId: string, timeout?: number): Promise<ProxySettings>;

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

if (!response)
return { browserId: '' };
throw new Error('[IE-0003] Unable to set the cookie because the browser ID could not be retrieved from the server. Try again later, or use try-catch blocks to handle this error.');
const { ref: browserId } = response;
return { browserId };
}
/**
* A function that gets the guest ref from CDP.
* A function that gets the guest ref from EP.
* @param browserId - The browser id of the client

@@ -9,3 +9,3 @@ * @param sitecoreEdgeContextId - The sitecoreEdgeContextId

export declare function getGuestId(browserId: string, sitecoreEdgeContextId: string, sitecoreEdgeUrl: string): Promise<string>;
interface IGetGuestRefCommon {
interface GetGuestRefCommon {
status: string;

@@ -15,3 +15,3 @@ version: string;

}
export interface IGetGuestRefResponse extends IGetGuestRefCommon {
export interface GetGuestRefResponse extends GetGuestRefCommon {
ref: string;

@@ -22,3 +22,3 @@ customer: {

}
export interface IGetGuestRefResponseError extends IGetGuestRefCommon {
export interface GetGuestRefResponseError extends GetGuestRefCommon {
error_msg: string;

@@ -25,0 +25,0 @@ moreInfo: string;

// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
import { API_VERSION, LIBRARY_VERSION } from '../consts';
/**
* A function that gets the guest ref from CDP.
* A function that gets the guest ref from EP.
* @param browserId - The browser id of the client

@@ -6,0 +6,0 @@ * @param sitecoreEdgeContextId - The sitecoreEdgeContextId

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

import { IHttpResponse, IMiddlewareNextResponse, TRequest } from '@sitecore-cloudsdk/utils';
import { ISettings, ISettingsParamsServer } from '../settings/interfaces';
export declare function setCoreSettings(settings: ISettings): void;
import { HttpResponse, MiddlewareNextResponse, Request } from '@sitecore-cloudsdk/utils';
import { Settings, SettingsParamsServer } from '../settings/interfaces';
export declare function setCoreSettings(settings: Settings): void;
/**

@@ -12,3 +12,3 @@ * Initializes the core settings for browser-based applications.

*/
export declare function getSettingsServer(): ISettings;
export declare function getSettingsServer(): Settings;
/**

@@ -22,2 +22,2 @@ * Initializes the core settings for browser-based applications.

*/
export declare function initCoreServer<TResponse extends IMiddlewareNextResponse | IHttpResponse>(settingsInput: ISettingsParamsServer, request: TRequest, response: TResponse): Promise<void>;
export declare function initCoreServer<Response extends MiddlewareNextResponse | HttpResponse>(settingsInput: SettingsParamsServer, request: Request, response: Response): Promise<void>;

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

if (!coreSettings) {
throw Error('[IE-0005] You must first initialize the "core" package. Run the "init" function.');
throw Error('[IE-0008] You must first initialize the "core" package. Run the "init" function.');
}

@@ -26,0 +26,0 @@ return coreSettings;

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

import { ISettings, ISettingsParamsBrowser } from '../settings/interfaces';
import { Settings, SettingsParamsBrowser } from '../settings/interfaces';
/**
* Enum representing the initialization statuses.
* - `NOT_STARTED`: The initialization process has not started.
* - `INITIALIZING`: The initialization process is in progress.
* - `DONE`: The initialization process is complete.
*/
export declare enum INIT_STATUSES {
NOT_STARTED = 0,
INITIALIZING = 1,
DONE = 2
}
export declare function setInitStatus(status: INIT_STATUSES): void;
export declare function setCoreSettings(settings: ISettings): void;
/**
* Retrieves the core settings object.

@@ -23,3 +10,3 @@ *

*/
export declare function getSettings(): ISettings;
export declare function getSettings(): Settings;
/**

@@ -33,2 +20,7 @@ * Initializes the core settings for browser-based applications.

*/
export declare function initCore(settingsInput: ISettingsParamsBrowser): Promise<void>;
export declare function initCore(settingsInput: SettingsParamsBrowser): Promise<void>;
/**
* Helper functions for tests
*/
export declare function setCoreSettings(settings: Settings): void;
export declare function setCookiePromise(promise: Promise<void>): void;

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

/**
* Enum representing the initialization statuses.
* - `NOT_STARTED`: The initialization process has not started.
* - `INITIALIZING`: The initialization process is in progress.
* - `DONE`: The initialization process is complete.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export var INIT_STATUSES;
(function (INIT_STATUSES) {
INIT_STATUSES[INIT_STATUSES["NOT_STARTED"] = 0] = "NOT_STARTED";
INIT_STATUSES[INIT_STATUSES["INITIALIZING"] = 1] = "INITIALIZING";
INIT_STATUSES[INIT_STATUSES["DONE"] = 2] = "DONE";
})(INIT_STATUSES || (INIT_STATUSES = {}));
/**
* Internal settings object to be used by all functions in module caching.

@@ -24,9 +11,2 @@ * It starts with a null value and is set to the proper object by the function. *

let coreSettings = null;
let initStatus = INIT_STATUSES.NOT_STARTED;
export function setInitStatus(status) {
initStatus = status;
}
export function setCoreSettings(settings) {
coreSettings = settings;
}
/**

@@ -42,6 +22,7 @@ * Retrieves the core settings object.

if (!coreSettings) {
throw Error(`[IE-0004] You must first initialize the "core" package. Run the "init" function.`);
throw Error(`[IE-0008] You must first initialize the "core" package. Run the "init" function.`);
}
return coreSettings;
}
let createCookiePromise = null;
/**

@@ -56,11 +37,16 @@ * Initializes the core settings for browser-based applications.

export async function initCore(settingsInput) {
if (initStatus != INIT_STATUSES.NOT_STARTED)
return;
setInitStatus(INIT_STATUSES.INITIALIZING);
coreSettings = createSettings(settingsInput);
setCoreSettings(coreSettings);
if (settingsInput.enableBrowserCookie) {
await createCookie(coreSettings);
}
setInitStatus(INIT_STATUSES.DONE);
if (coreSettings === null)
coreSettings = createSettings(settingsInput);
if (settingsInput.enableBrowserCookie && createCookiePromise === null)
createCookiePromise = createCookie(coreSettings);
await createCookiePromise;
}
/**
* Helper functions for tests
*/
export function setCoreSettings(settings) {
coreSettings = settings;
}
export function setCookiePromise(promise) {
createCookiePromise = promise;
}
/**
* The response object that Sitecore CDP returns
* The response object that Sitecore EP returns
*/
export interface ICdpResponse {
export interface EPResponse {
ref: string;

@@ -10,3 +10,3 @@ status: string;

}
export interface IProxySettings {
export interface ProxySettings {
browserId: string;

@@ -17,5 +17,5 @@ }

*/
export interface IInfer {
export interface Infer {
language: () => string | undefined;
pageName: () => string;
}

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

import { ISettings, ISettingsParams } from './interfaces';
import { Settings, SettingsParams } from './interfaces';
/**
* Creates the global settings object, to be used by the library
* @param settingsInput - Global settings added by the developer.
* @returns an ISettings with the settings added by the developer
* @returns an Settings with the settings added by the developer
*/
export declare function createSettings(settingsInput: ISettingsParams): ISettings;
export declare function createSettings(settingsInput: SettingsParams): Settings;

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

* @param settingsInput - Global settings added by the developer.
* @returns an ISettings with the settings added by the developer
* @returns an Settings with the settings added by the developer
*/

@@ -10,0 +10,0 @@ export function createSettings(settingsInput) {

/**
* Extends the global settings object with additional properties
*/
export interface ISettings extends IBasicSettings {
cookieSettings: ICookieSettings;
export interface Settings extends BasicSettings {
cookieSettings: CookieSettings;
sitecoreEdgeUrl: string;
}
export interface ISettingsParamsBrowser extends ISettingsParams {
export interface SettingsParamsBrowser extends SettingsParams {
enableBrowserCookie?: boolean;
}
export interface ISettingsParamsServer extends ISettingsParams {
export interface SettingsParamsServer extends SettingsParams {
enableServerCookie?: boolean;
}
export interface ISettingsParams extends IBasicSettings, ICookieSettingsInput {
export interface SettingsParams extends BasicSettings, CookieSettingsInput {
timeout?: number;

@@ -21,7 +21,7 @@ sitecoreEdgeUrl?: string;

*/
interface IBasicSettings {
interface BasicSettings {
sitecoreEdgeContextId: string;
siteName: string;
}
interface ICookieSettingsInput {
interface CookieSettingsInput {
cookiePath?: string;

@@ -34,3 +34,3 @@ cookieExpiryDays?: number;

*/
export interface ICookieSettings {
export interface CookieSettings {
cookieName: string;

@@ -44,23 +44,5 @@ cookieDomain?: string;

*/
export interface ICookieSettingsBrowser extends ICookieSettings {
export interface CookieSettingsBrowser extends CookieSettings {
enableBrowserCookie: boolean;
}
/**
* Properties for the Web Flow configuration
*/
export interface IWebPersonalizationConfig {
asyncScriptLoading?: boolean;
deferScriptLoading?: boolean;
baseURLOverride?: string;
}
export interface IWebExperiencesSettings {
targetURL: string;
pointOfSale: string;
client_key: string;
web_flow_config: {
async: boolean;
defer: boolean;
};
web_flow_target?: string;
}
export {};

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

import { ISettingsParams } from './interfaces';
import { SettingsParams } from './interfaces';
/**

@@ -10,2 +10,2 @@ * Validates the core settings to ensure they meet required criteria.

*/
export declare function validateSettings(settings: ISettingsParams): void;
export declare function validateSettings(settings: SettingsParams): void;
{
"name": "@sitecore-cloudsdk/core",
"version": "0.1.1",
"version": "0.1.2",
"license": "Apache-2.0",

@@ -5,0 +5,0 @@ "main": "dist/cjs/src/index.js",

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