@sitecore-cloudsdk/core 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/index.d.ts +2 -2
- package/dist/cjs/src/lib/cookie/create-cookie.d.ts +3 -3
- package/dist/cjs/src/lib/cookie/create-cookie.js +3 -5
- package/dist/cjs/src/lib/cookie/get-browser-id-from-middleware-request.d.ts +2 -2
- package/dist/cjs/src/lib/cookie/get-browser-id-from-request.d.ts +2 -2
- package/dist/cjs/src/lib/cookie/get-default-cookie-attributes.d.ts +2 -2
- package/dist/cjs/src/lib/cookie/handle-http-cookie.d.ts +4 -4
- package/dist/cjs/src/lib/cookie/handle-http-cookie.js +4 -7
- package/dist/cjs/src/lib/cookie/handle-next-js-middleware-cookie.d.ts +3 -3
- package/dist/cjs/src/lib/cookie/handle-next-js-middleware-cookie.js +3 -6
- package/dist/cjs/src/lib/cookie/handle-server-cookie.d.ts +2 -2
- package/dist/cjs/src/lib/init/fetch-browser-id-from-edge-proxy.d.ts +2 -2
- package/dist/cjs/src/lib/init/fetch-browser-id-from-edge-proxy.js +6 -6
- package/dist/cjs/src/lib/init/get-guest-id.d.ts +4 -4
- package/dist/cjs/src/lib/init/get-guest-id.js +1 -1
- package/dist/cjs/src/lib/init/init-core-server.d.ts +5 -5
- package/dist/cjs/src/lib/init/init-core-server.js +1 -1
- package/dist/cjs/src/lib/init/init-core.d.ts +8 -16
- package/dist/cjs/src/lib/init/init-core.js +19 -33
- package/dist/cjs/src/lib/interfaces.d.ts +4 -4
- package/dist/cjs/src/lib/settings/create-settings.d.ts +3 -3
- package/dist/cjs/src/lib/settings/create-settings.js +1 -1
- package/dist/cjs/src/lib/settings/interfaces.d.ts +9 -27
- package/dist/cjs/src/lib/settings/validate-settings.d.ts +2 -2
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/package.json +1 -1
- package/dist/esm/src/index.d.ts +2 -2
- package/dist/esm/src/lib/cookie/create-cookie.d.ts +3 -3
- package/dist/esm/src/lib/cookie/create-cookie.js +3 -5
- package/dist/esm/src/lib/cookie/get-browser-id-from-middleware-request.d.ts +2 -2
- package/dist/esm/src/lib/cookie/get-browser-id-from-request.d.ts +2 -2
- package/dist/esm/src/lib/cookie/get-default-cookie-attributes.d.ts +2 -2
- package/dist/esm/src/lib/cookie/handle-http-cookie.d.ts +4 -4
- package/dist/esm/src/lib/cookie/handle-http-cookie.js +4 -7
- package/dist/esm/src/lib/cookie/handle-next-js-middleware-cookie.d.ts +3 -3
- package/dist/esm/src/lib/cookie/handle-next-js-middleware-cookie.js +3 -6
- package/dist/esm/src/lib/cookie/handle-server-cookie.d.ts +2 -2
- package/dist/esm/src/lib/init/fetch-browser-id-from-edge-proxy.d.ts +2 -2
- package/dist/esm/src/lib/init/fetch-browser-id-from-edge-proxy.js +6 -6
- package/dist/esm/src/lib/init/get-guest-id.d.ts +4 -4
- package/dist/esm/src/lib/init/get-guest-id.js +1 -1
- package/dist/esm/src/lib/init/init-core-server.d.ts +5 -5
- package/dist/esm/src/lib/init/init-core-server.js +1 -1
- package/dist/esm/src/lib/init/init-core.d.ts +8 -16
- package/dist/esm/src/lib/init/init-core.js +16 -30
- package/dist/esm/src/lib/interfaces.d.ts +4 -4
- package/dist/esm/src/lib/settings/create-settings.d.ts +3 -3
- package/dist/esm/src/lib/settings/create-settings.js +1 -1
- package/dist/esm/src/lib/settings/interfaces.d.ts +9 -27
- package/dist/esm/src/lib/settings/validate-settings.d.ts +2 -2
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/cjs/package.json
CHANGED
package/dist/cjs/src/index.d.ts
CHANGED
|
@@ -14,5 +14,5 @@ export { validateSettings } from './lib/settings/validate-settings';
|
|
|
14
14
|
export { language, pageName } from './lib/infer/infer';
|
|
15
15
|
export { getBrowserIdFromRequest } from './lib/cookie/get-browser-id-from-request';
|
|
16
16
|
export { API_VERSION, COOKIE_NAME_PREFIX, DAILY_SECONDS, DEFAULT_COOKIE_EXPIRY_DAYS, LIBRARY_VERSION, SITECORE_EDGE_URL, } from './lib/consts';
|
|
17
|
-
export type {
|
|
18
|
-
export type {
|
|
17
|
+
export type { EPResponse, Infer } from './lib/interfaces';
|
|
18
|
+
export type { CookieSettings, Settings, SettingsParamsBrowser, SettingsParamsServer } from './lib/settings/interfaces';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Settings } from '../settings/interfaces';
|
|
2
2
|
/**
|
|
3
3
|
* Creates and adds the cookie to the document
|
|
4
|
-
* @param settings - The
|
|
4
|
+
* @param settings - The CookieSettings settings object
|
|
5
5
|
* @returns - browserId or undefined on error
|
|
6
6
|
*/
|
|
7
|
-
export declare function createCookie(settings:
|
|
7
|
+
export declare function createCookie(settings: Settings): Promise<void>;
|
|
@@ -7,16 +7,14 @@ const get_default_cookie_attributes_1 = require("./get-default-cookie-attributes
|
|
|
7
7
|
const fetch_browser_id_from_edge_proxy_1 = require("../init/fetch-browser-id-from-edge-proxy");
|
|
8
8
|
/**
|
|
9
9
|
* Creates and adds the cookie to the document
|
|
10
|
-
* @param settings - The
|
|
10
|
+
* @param settings - The CookieSettings settings object
|
|
11
11
|
* @returns - browserId or undefined on error
|
|
12
12
|
*/
|
|
13
13
|
async function createCookie(settings) {
|
|
14
14
|
if ((0, utils_1.cookieExists)(window.document.cookie, settings.cookieSettings.cookieName))
|
|
15
15
|
return;
|
|
16
16
|
const { browserId } = await (0, fetch_browser_id_from_edge_proxy_1.fetchBrowserIdFromEdgeProxy)(settings.sitecoreEdgeUrl, settings.sitecoreEdgeContextId);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
document.cookie = (0, utils_1.createCookieString)(settings.cookieSettings.cookieName, browserId, attributes);
|
|
20
|
-
}
|
|
17
|
+
const attributes = (0, get_default_cookie_attributes_1.getDefaultCookieAttributes)(settings.cookieSettings.cookieExpiryDays, settings.cookieSettings.cookieDomain);
|
|
18
|
+
document.cookie = (0, utils_1.createCookieString)(settings.cookieSettings.cookieName, browserId, attributes);
|
|
21
19
|
}
|
|
22
20
|
exports.createCookie = createCookie;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MiddlewareRequest } from '@sitecore-cloudsdk/utils';
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves the browser ID from the provided Middleware Request by extracting the cookie value
|
|
4
4
|
* associated with the specified 'cookieName'. The function first checks for Next.js v12 cookie values,
|
|
@@ -8,4 +8,4 @@ import { IMiddlewareRequest } from '@sitecore-cloudsdk/utils';
|
|
|
8
8
|
* @param cookieName - The name of the cookie to retrieve.
|
|
9
9
|
* @returns The browser ID extracted from the cookie, or undefined if not found.
|
|
10
10
|
*/
|
|
11
|
-
export declare function getBrowserIdFromMiddlewareRequest(request:
|
|
11
|
+
export declare function getBrowserIdFromMiddlewareRequest(request: MiddlewareRequest, cookieName: string): string | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Request } from '@sitecore-cloudsdk/utils';
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves the browser ID from the provided request object ('T'), using the specified 'cookieName'.
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@ import { TRequest } from '@sitecore-cloudsdk/utils';
|
|
|
6
6
|
* @param cookieName - The name of the cookie to retrieve the browser ID from.
|
|
7
7
|
* @returns The browser ID extracted from the cookie or an empty string if not found.
|
|
8
8
|
*/
|
|
9
|
-
export declare function getBrowserIdFromRequest<T extends
|
|
9
|
+
export declare function getBrowserIdFromRequest<T extends Request>(request: T, cookieName: string): string;
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* @param maxAge - Set the cookie "Max-Age" attribute in days.
|
|
4
4
|
* @returns the default configuration settings for the cookie string
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
export declare function getDefaultCookieAttributes(maxAge?: number, cookieDomain?: string):
|
|
6
|
+
import { CookieProperties } from '@sitecore-cloudsdk/utils';
|
|
7
|
+
export declare function getDefaultCookieAttributes(maxAge?: number, cookieDomain?: string): CookieProperties;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { HttpRequest, HttpResponse } from '@sitecore-cloudsdk/utils';
|
|
2
|
+
import { Settings } from '../settings/interfaces';
|
|
3
3
|
/**
|
|
4
4
|
* Handles HTTP Cookie operations for setting the browser ID cookie in the request and response.
|
|
5
5
|
*
|
|
@@ -9,6 +9,6 @@ import { ISettings } from '../settings/interfaces';
|
|
|
9
9
|
* @param timeout - The timeout for the call to proxy to get browserId.
|
|
10
10
|
* @returns A Promise that resolves once the browser ID cookie is handled.
|
|
11
11
|
*
|
|
12
|
-
* @throws [IE-0003] - This exception is thrown in the case
|
|
12
|
+
* @throws [IE-0003] - This exception is thrown in the case getBrowserIdFromEP wasn't able to retrieve a browser id.
|
|
13
13
|
*/
|
|
14
|
-
export declare function handleHttpCookie(request:
|
|
14
|
+
export declare function handleHttpCookie(request: HttpRequest, response: HttpResponse, options: Settings, timeout?: number): Promise<void>;
|
|
@@ -14,7 +14,7 @@ const fetch_browser_id_from_edge_proxy_1 = require("../init/fetch-browser-id-fro
|
|
|
14
14
|
* @param timeout - The timeout for the call to proxy to get browserId.
|
|
15
15
|
* @returns A Promise that resolves once the browser ID cookie is handled.
|
|
16
16
|
*
|
|
17
|
-
* @throws [IE-0003] - This exception is thrown in the case
|
|
17
|
+
* @throws [IE-0003] - This exception is thrown in the case getBrowserIdFromEP wasn't able to retrieve a browser id.
|
|
18
18
|
*/
|
|
19
19
|
async function handleHttpCookie(request, response, options, timeout) {
|
|
20
20
|
const { cookieName } = options.cookieSettings;
|
|
@@ -26,12 +26,9 @@ async function handleHttpCookie(request, response, options, timeout) {
|
|
|
26
26
|
if (cookie)
|
|
27
27
|
cookieValue = cookie.value;
|
|
28
28
|
}
|
|
29
|
-
if (!cookieValue)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
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.');
|
|
33
|
-
cookieValue = browserId;
|
|
34
|
-
}
|
|
29
|
+
if (!cookieValue)
|
|
30
|
+
cookieValue = (await (0, fetch_browser_id_from_edge_proxy_1.fetchBrowserIdFromEdgeProxy)(options.sitecoreEdgeUrl, options.sitecoreEdgeContextId, timeout))
|
|
31
|
+
.browserId;
|
|
35
32
|
const defaultCookieAttributes = (0, get_default_cookie_attributes_1.getDefaultCookieAttributes)(options.cookieSettings.cookieExpiryDays, options.cookieSettings.cookieDomain);
|
|
36
33
|
const cookieString = (0, utils_1.createCookieString)(cookieName, cookieValue, defaultCookieAttributes);
|
|
37
34
|
if (!cookie)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { MiddlewareNextResponse, MiddlewareRequest } from '@sitecore-cloudsdk/utils';
|
|
2
|
+
import { Settings } from '../settings/interfaces';
|
|
3
3
|
/**
|
|
4
4
|
* Handles the Middleware Request and sets a cookie with the provided 'cookieName' and 'cookieValue'.
|
|
5
5
|
* If 'cookieValue' is not present in the request, it fetches it using the 'fetchBrowserIdFromEdgeProxy' function
|
|
@@ -13,4 +13,4 @@ import { ISettings } from '../settings/interfaces';
|
|
|
13
13
|
* @throws [IE-0003] - This exception is thrown in the case fetchBrowserIdFromEdgeProxy wasn't able to retrieve a browserId.
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
|
-
export declare function handleNextJsMiddlewareCookie(request:
|
|
16
|
+
export declare function handleNextJsMiddlewareCookie(request: MiddlewareRequest, response: MiddlewareNextResponse, options: Settings, timeout?: number): Promise<void>;
|
|
@@ -21,12 +21,9 @@ const fetch_browser_id_from_edge_proxy_1 = require("../init/fetch-browser-id-fro
|
|
|
21
21
|
async function handleNextJsMiddlewareCookie(request, response, options, timeout) {
|
|
22
22
|
const { cookieName } = options.cookieSettings;
|
|
23
23
|
let cookieValue = (0, get_browser_id_from_middleware_request_1.getBrowserIdFromMiddlewareRequest)(request, cookieName);
|
|
24
|
-
if (!cookieValue)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
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.');
|
|
28
|
-
cookieValue = browserId;
|
|
29
|
-
}
|
|
24
|
+
if (!cookieValue)
|
|
25
|
+
cookieValue = (await (0, fetch_browser_id_from_edge_proxy_1.fetchBrowserIdFromEdgeProxy)(options.sitecoreEdgeUrl, options.sitecoreEdgeContextId, timeout))
|
|
26
|
+
.browserId;
|
|
30
27
|
const defaultCookieAttributes = (0, get_default_cookie_attributes_1.getDefaultCookieAttributes)(options.cookieSettings.cookieExpiryDays, options.cookieSettings.cookieDomain);
|
|
31
28
|
request.cookies.set(cookieName, cookieValue, defaultCookieAttributes);
|
|
32
29
|
response.cookies.set(cookieName, cookieValue, defaultCookieAttributes);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Request, type MiddlewareNextResponse, type HttpResponse } from '@sitecore-cloudsdk/utils';
|
|
2
2
|
/**
|
|
3
3
|
* Handles server-side cookie operations based on the provided 'request' and 'response' objects.
|
|
4
4
|
*
|
|
@@ -7,4 +7,4 @@ import { type TRequest, type IMiddlewareNextResponse, type IHttpResponse } from
|
|
|
7
7
|
* @param timeout - The timeout for the call to proxy to get browserId.
|
|
8
8
|
* @returns A Promise that resolves once the cookie handling is complete.
|
|
9
9
|
*/
|
|
10
|
-
export declare function handleServerCookie<T extends
|
|
10
|
+
export declare function handleServerCookie<T extends Request, X extends MiddlewareNextResponse | HttpResponse>(request: T, response: X, timeout?: number): Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProxySettings } from '../interfaces';
|
|
2
2
|
/**
|
|
3
3
|
* Gets the browser ID and Client Key from Sitecore Edge Proxy
|
|
4
4
|
* @param sitecoreEdgeUrl - The baseURL for the Edge Proxy API.
|
|
@@ -6,4 +6,4 @@ import { IProxySettings } from '../interfaces';
|
|
|
6
6
|
* @param timeout - The timeout for the call to proxy
|
|
7
7
|
* @returns the browser ID
|
|
8
8
|
*/
|
|
9
|
-
export declare function fetchBrowserIdFromEdgeProxy(sitecoreEdgeUrl: string, sitecoreEdgeContextId: string, timeout?: number): Promise<
|
|
9
|
+
export declare function fetchBrowserIdFromEdgeProxy(sitecoreEdgeUrl: string, sitecoreEdgeContextId: string, timeout?: number): Promise<ProxySettings>;
|
|
@@ -18,19 +18,19 @@ async function fetchBrowserIdFromEdgeProxy(sitecoreEdgeUrl, sitecoreEdgeContextI
|
|
|
18
18
|
headers: { 'X-Library-Version': consts_1.LIBRARY_VERSION },
|
|
19
19
|
};
|
|
20
20
|
const url = (0, construct_get_browser_id_url_1.constructGetBrowserIdUrl)(sitecoreEdgeUrl, sitecoreEdgeContextId);
|
|
21
|
-
let
|
|
21
|
+
let payload;
|
|
22
22
|
if (timeout !== undefined) {
|
|
23
|
-
|
|
23
|
+
payload = await (0, utils_1.fetchWithTimeout)(url, timeout, fetchOptions);
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
|
|
26
|
+
payload = await fetch(url, fetchOptions)
|
|
27
27
|
.then((res) => res.json())
|
|
28
28
|
.then((data) => data)
|
|
29
29
|
.catch(() => undefined);
|
|
30
30
|
}
|
|
31
|
-
if (!
|
|
32
|
-
|
|
33
|
-
const { ref: browserId } =
|
|
31
|
+
if (!payload?.ref)
|
|
32
|
+
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.');
|
|
33
|
+
const { ref: browserId } = payload;
|
|
34
34
|
return { browserId };
|
|
35
35
|
}
|
|
36
36
|
exports.fetchBrowserIdFromEdgeProxy = fetchBrowserIdFromEdgeProxy;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A function that gets the guest ref from
|
|
2
|
+
* A function that gets the guest ref from EP.
|
|
3
3
|
* @param browserId - The browser id of the client
|
|
4
4
|
* @param sitecoreEdgeContextId - The sitecoreEdgeContextId
|
|
5
5
|
* @returns - A promise that resolves with the guest ref
|
|
6
6
|
* @throws - Will throw an error if the clientKey/browser id is invalid
|
|
7
7
|
*/
|
|
8
8
|
export declare function getGuestId(browserId: string, sitecoreEdgeContextId: string, sitecoreEdgeUrl: string): Promise<string>;
|
|
9
|
-
interface
|
|
9
|
+
interface GetGuestRefCommon {
|
|
10
10
|
status: string;
|
|
11
11
|
version: string;
|
|
12
12
|
clientKey: string;
|
|
13
13
|
}
|
|
14
|
-
export interface
|
|
14
|
+
export interface GetGuestRefResponse extends GetGuestRefCommon {
|
|
15
15
|
ref: string;
|
|
16
16
|
customer: {
|
|
17
17
|
ref: string;
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
export interface
|
|
20
|
+
export interface GetGuestRefResponseError extends GetGuestRefCommon {
|
|
21
21
|
error_msg: string;
|
|
22
22
|
moreInfo: string;
|
|
23
23
|
}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.getGuestId = void 0;
|
|
5
5
|
const consts_1 = require("../consts");
|
|
6
6
|
/**
|
|
7
|
-
* A function that gets the guest ref from
|
|
7
|
+
* A function that gets the guest ref from EP.
|
|
8
8
|
* @param browserId - The browser id of the client
|
|
9
9
|
* @param sitecoreEdgeContextId - The sitecoreEdgeContextId
|
|
10
10
|
* @returns - A promise that resolves with the guest ref
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare function setCoreSettings(settings:
|
|
1
|
+
import { HttpResponse, MiddlewareNextResponse, Request } from '@sitecore-cloudsdk/utils';
|
|
2
|
+
import { Settings, SettingsParamsServer } from '../settings/interfaces';
|
|
3
|
+
export declare function setCoreSettings(settings: Settings): void;
|
|
4
4
|
/**
|
|
5
5
|
* Initializes the core settings for browser-based applications.
|
|
6
6
|
*
|
|
@@ -9,7 +9,7 @@ export declare function setCoreSettings(settings: ISettings): void;
|
|
|
9
9
|
* @param settingsInput - The settings input to configure the core settings.
|
|
10
10
|
* @returns A Promise that resolves when initialization is complete.
|
|
11
11
|
*/
|
|
12
|
-
export declare function getSettingsServer():
|
|
12
|
+
export declare function getSettingsServer(): Settings;
|
|
13
13
|
/**
|
|
14
14
|
* Initializes the core settings for browser-based applications.
|
|
15
15
|
*
|
|
@@ -18,4 +18,4 @@ export declare function getSettingsServer(): ISettings;
|
|
|
18
18
|
* @param settingsInput - The settings input to configure the core settings.
|
|
19
19
|
* @returns A Promise that resolves when initialization is complete.
|
|
20
20
|
*/
|
|
21
|
-
export declare function initCoreServer<
|
|
21
|
+
export declare function initCoreServer<Response extends MiddlewareNextResponse | HttpResponse>(settingsInput: SettingsParamsServer, request: Request, response: Response): Promise<void>;
|
|
@@ -24,7 +24,7 @@ exports.setCoreSettings = setCoreSettings;
|
|
|
24
24
|
*/
|
|
25
25
|
function getSettingsServer() {
|
|
26
26
|
if (!coreSettings) {
|
|
27
|
-
throw Error('[IE-
|
|
27
|
+
throw Error('[IE-0008] You must first initialize the "core" package. Run the "init" function.');
|
|
28
28
|
}
|
|
29
29
|
return coreSettings;
|
|
30
30
|
}
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/**
|
|
3
|
-
* Enum representing the initialization statuses.
|
|
4
|
-
* - `NOT_STARTED`: The initialization process has not started.
|
|
5
|
-
* - `INITIALIZING`: The initialization process is in progress.
|
|
6
|
-
* - `DONE`: The initialization process is complete.
|
|
7
|
-
*/
|
|
8
|
-
export declare enum INIT_STATUSES {
|
|
9
|
-
NOT_STARTED = 0,
|
|
10
|
-
INITIALIZING = 1,
|
|
11
|
-
DONE = 2
|
|
12
|
-
}
|
|
13
|
-
export declare function setInitStatus(status: INIT_STATUSES): void;
|
|
14
|
-
export declare function setCoreSettings(settings: ISettings): void;
|
|
1
|
+
import { Settings, SettingsParamsBrowser } from '../settings/interfaces';
|
|
15
2
|
/**
|
|
16
3
|
* Retrieves the core settings object.
|
|
17
4
|
*
|
|
@@ -20,7 +7,7 @@ export declare function setCoreSettings(settings: ISettings): void;
|
|
|
20
7
|
* @returns The core settings object.
|
|
21
8
|
* @throws Error if the core settings haven't been initialized with the required properties.
|
|
22
9
|
*/
|
|
23
|
-
export declare function getSettings():
|
|
10
|
+
export declare function getSettings(): Settings;
|
|
24
11
|
/**
|
|
25
12
|
* Initializes the core settings for browser-based applications.
|
|
26
13
|
*
|
|
@@ -29,4 +16,9 @@ export declare function getSettings(): ISettings;
|
|
|
29
16
|
* @param settingsInput - The settings input to configure the core settings.
|
|
30
17
|
* @returns A Promise that resolves when initialization is complete.
|
|
31
18
|
*/
|
|
32
|
-
export declare function initCore(settingsInput:
|
|
19
|
+
export declare function initCore(settingsInput: SettingsParamsBrowser): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Helper functions for tests
|
|
22
|
+
*/
|
|
23
|
+
export declare function setCoreSettings(settings: Settings): void;
|
|
24
|
+
export declare function setCookiePromise(promise: Promise<void>): void;
|
|
@@ -1,37 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.setCookiePromise = exports.setCoreSettings = exports.initCore = exports.getSettings = void 0;
|
|
4
4
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
5
|
const create_cookie_1 = require("../cookie/create-cookie");
|
|
6
6
|
const create_settings_1 = require("../settings/create-settings");
|
|
7
|
-
/**
|
|
8
|
-
* Enum representing the initialization statuses.
|
|
9
|
-
* - `NOT_STARTED`: The initialization process has not started.
|
|
10
|
-
* - `INITIALIZING`: The initialization process is in progress.
|
|
11
|
-
* - `DONE`: The initialization process is complete.
|
|
12
|
-
*/
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
14
|
-
var INIT_STATUSES;
|
|
15
|
-
(function (INIT_STATUSES) {
|
|
16
|
-
INIT_STATUSES[INIT_STATUSES["NOT_STARTED"] = 0] = "NOT_STARTED";
|
|
17
|
-
INIT_STATUSES[INIT_STATUSES["INITIALIZING"] = 1] = "INITIALIZING";
|
|
18
|
-
INIT_STATUSES[INIT_STATUSES["DONE"] = 2] = "DONE";
|
|
19
|
-
})(INIT_STATUSES || (exports.INIT_STATUSES = INIT_STATUSES = {}));
|
|
20
7
|
/**
|
|
21
8
|
* Internal settings object to be used by all functions in module caching.
|
|
22
9
|
* It starts with a null value and is set to the proper object by the function. *
|
|
23
10
|
* Can be retrieved only through the function.
|
|
24
11
|
*/
|
|
25
12
|
let coreSettings = null;
|
|
26
|
-
let initStatus = INIT_STATUSES.NOT_STARTED;
|
|
27
|
-
function setInitStatus(status) {
|
|
28
|
-
initStatus = status;
|
|
29
|
-
}
|
|
30
|
-
exports.setInitStatus = setInitStatus;
|
|
31
|
-
function setCoreSettings(settings) {
|
|
32
|
-
coreSettings = settings;
|
|
33
|
-
}
|
|
34
|
-
exports.setCoreSettings = setCoreSettings;
|
|
35
13
|
/**
|
|
36
14
|
* Retrieves the core settings object.
|
|
37
15
|
*
|
|
@@ -42,11 +20,12 @@ exports.setCoreSettings = setCoreSettings;
|
|
|
42
20
|
*/
|
|
43
21
|
function getSettings() {
|
|
44
22
|
if (!coreSettings) {
|
|
45
|
-
throw Error(`[IE-
|
|
23
|
+
throw Error(`[IE-0008] You must first initialize the "core" package. Run the "init" function.`);
|
|
46
24
|
}
|
|
47
25
|
return coreSettings;
|
|
48
26
|
}
|
|
49
27
|
exports.getSettings = getSettings;
|
|
28
|
+
let createCookiePromise = null;
|
|
50
29
|
/**
|
|
51
30
|
* Initializes the core settings for browser-based applications.
|
|
52
31
|
*
|
|
@@ -56,14 +35,21 @@ exports.getSettings = getSettings;
|
|
|
56
35
|
* @returns A Promise that resolves when initialization is complete.
|
|
57
36
|
*/
|
|
58
37
|
async function initCore(settingsInput) {
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (settingsInput.enableBrowserCookie) {
|
|
65
|
-
await (0, create_cookie_1.createCookie)(coreSettings);
|
|
66
|
-
}
|
|
67
|
-
setInitStatus(INIT_STATUSES.DONE);
|
|
38
|
+
if (coreSettings === null)
|
|
39
|
+
coreSettings = (0, create_settings_1.createSettings)(settingsInput);
|
|
40
|
+
if (settingsInput.enableBrowserCookie && createCookiePromise === null)
|
|
41
|
+
createCookiePromise = (0, create_cookie_1.createCookie)(coreSettings);
|
|
42
|
+
await createCookiePromise;
|
|
68
43
|
}
|
|
69
44
|
exports.initCore = initCore;
|
|
45
|
+
/**
|
|
46
|
+
* Helper functions for tests
|
|
47
|
+
*/
|
|
48
|
+
function setCoreSettings(settings) {
|
|
49
|
+
coreSettings = settings;
|
|
50
|
+
}
|
|
51
|
+
exports.setCoreSettings = setCoreSettings;
|
|
52
|
+
function setCookiePromise(promise) {
|
|
53
|
+
createCookiePromise = promise;
|
|
54
|
+
}
|
|
55
|
+
exports.setCookiePromise = setCookiePromise;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The response object that Sitecore
|
|
2
|
+
* The response object that Sitecore EP returns
|
|
3
3
|
*/
|
|
4
|
-
export interface
|
|
4
|
+
export interface EPResponse {
|
|
5
5
|
ref: string;
|
|
6
6
|
status: string;
|
|
7
7
|
version: string;
|
|
8
8
|
client_key: string;
|
|
9
9
|
}
|
|
10
|
-
export interface
|
|
10
|
+
export interface ProxySettings {
|
|
11
11
|
browserId: string;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Interface for supporting response IncomingMessage http node type
|
|
15
15
|
*/
|
|
16
|
-
export interface
|
|
16
|
+
export interface Infer {
|
|
17
17
|
language: () => string | undefined;
|
|
18
18
|
pageName: () => string;
|
|
19
19
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Settings, SettingsParams } from './interfaces';
|
|
2
2
|
/**
|
|
3
3
|
* Creates the global settings object, to be used by the library
|
|
4
4
|
* @param settingsInput - Global settings added by the developer.
|
|
5
|
-
* @returns an
|
|
5
|
+
* @returns an Settings with the settings added by the developer
|
|
6
6
|
*/
|
|
7
|
-
export declare function createSettings(settingsInput:
|
|
7
|
+
export declare function createSettings(settingsInput: SettingsParams): Settings;
|
|
@@ -7,7 +7,7 @@ const validate_settings_1 = require("./validate-settings");
|
|
|
7
7
|
/**
|
|
8
8
|
* Creates the global settings object, to be used by the library
|
|
9
9
|
* @param settingsInput - Global settings added by the developer.
|
|
10
|
-
* @returns an
|
|
10
|
+
* @returns an Settings with the settings added by the developer
|
|
11
11
|
*/
|
|
12
12
|
function createSettings(settingsInput) {
|
|
13
13
|
(0, validate_settings_1.validateSettings)(settingsInput);
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Extends the global settings object with additional properties
|
|
3
3
|
*/
|
|
4
|
-
export interface
|
|
5
|
-
cookieSettings:
|
|
4
|
+
export interface Settings extends BasicSettings {
|
|
5
|
+
cookieSettings: CookieSettings;
|
|
6
6
|
sitecoreEdgeUrl: string;
|
|
7
7
|
}
|
|
8
|
-
export interface
|
|
8
|
+
export interface SettingsParamsBrowser extends SettingsParams {
|
|
9
9
|
enableBrowserCookie?: boolean;
|
|
10
10
|
}
|
|
11
|
-
export interface
|
|
11
|
+
export interface SettingsParamsServer extends SettingsParams {
|
|
12
12
|
enableServerCookie?: boolean;
|
|
13
13
|
}
|
|
14
|
-
export interface
|
|
14
|
+
export interface SettingsParams extends BasicSettings, CookieSettingsInput {
|
|
15
15
|
timeout?: number;
|
|
16
16
|
sitecoreEdgeUrl?: string;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Properties for the global settings object
|
|
20
20
|
*/
|
|
21
|
-
interface
|
|
21
|
+
interface BasicSettings {
|
|
22
22
|
sitecoreEdgeContextId: string;
|
|
23
23
|
siteName: string;
|
|
24
24
|
}
|
|
25
|
-
interface
|
|
25
|
+
interface CookieSettingsInput {
|
|
26
26
|
cookiePath?: string;
|
|
27
27
|
cookieExpiryDays?: number;
|
|
28
28
|
cookieDomain?: string;
|
|
@@ -30,7 +30,7 @@ interface ICookieSettingsInput {
|
|
|
30
30
|
/**
|
|
31
31
|
* Properties for the cookie object
|
|
32
32
|
*/
|
|
33
|
-
export interface
|
|
33
|
+
export interface CookieSettings {
|
|
34
34
|
cookieName: string;
|
|
35
35
|
cookieDomain?: string;
|
|
36
36
|
cookieExpiryDays: number;
|
|
@@ -39,25 +39,7 @@ export interface ICookieSettings {
|
|
|
39
39
|
/**
|
|
40
40
|
* Properties for the cookie object
|
|
41
41
|
*/
|
|
42
|
-
export interface
|
|
42
|
+
export interface CookieSettingsBrowser extends CookieSettings {
|
|
43
43
|
enableBrowserCookie: boolean;
|
|
44
44
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Properties for the Web Flow configuration
|
|
47
|
-
*/
|
|
48
|
-
export interface IWebPersonalizationConfig {
|
|
49
|
-
asyncScriptLoading?: boolean;
|
|
50
|
-
deferScriptLoading?: boolean;
|
|
51
|
-
baseURLOverride?: string;
|
|
52
|
-
}
|
|
53
|
-
export interface IWebExperiencesSettings {
|
|
54
|
-
targetURL: string;
|
|
55
|
-
pointOfSale: string;
|
|
56
|
-
client_key: string;
|
|
57
|
-
web_flow_config: {
|
|
58
|
-
async: boolean;
|
|
59
|
-
defer: boolean;
|
|
60
|
-
};
|
|
61
|
-
web_flow_target?: string;
|
|
62
|
-
}
|
|
63
45
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SettingsParams } from './interfaces';
|
|
2
2
|
/**
|
|
3
3
|
* Validates the core settings to ensure they meet required criteria.
|
|
4
4
|
*
|
|
@@ -7,4 +7,4 @@ import { ISettingsParams } from './interfaces';
|
|
|
7
7
|
* @param settings - The core settings object to validate.
|
|
8
8
|
* @throws Error with specific error codes if any required property is missing or empty.
|
|
9
9
|
*/
|
|
10
|
-
export declare function validateSettings(settings:
|
|
10
|
+
export declare function validateSettings(settings: SettingsParams): void;
|