@sitecore-cloudsdk/core 0.2.4 → 0.3.1-rc.0
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 +3 -4
- package/dist/cjs/src/index.d.ts +8 -7
- package/dist/cjs/src/index.js +14 -10
- package/dist/cjs/src/lib/consts.d.ts +9 -0
- package/dist/cjs/src/lib/consts.js +13 -1
- package/dist/cjs/src/lib/cookie/create-cookies.d.ts +6 -0
- package/dist/cjs/src/lib/cookie/create-cookies.js +28 -0
- package/dist/cjs/src/lib/cookie/get-browser-id.js +1 -1
- package/dist/cjs/src/lib/cookie/get-cookie-value-from-middleware-request.d.ts +11 -0
- package/dist/cjs/src/lib/cookie/{get-browser-id-from-middleware-request.js → get-cookie-value-from-middleware-request.js} +6 -6
- package/dist/cjs/src/lib/cookie/get-cookie-value-from-request.d.ts +9 -0
- package/dist/cjs/src/lib/cookie/get-cookie-value-from-request.js +24 -0
- package/dist/cjs/src/lib/cookie/get-default-cookie-attributes.d.ts +1 -1
- package/dist/cjs/src/lib/cookie/get-default-cookie-attributes.js +4 -5
- package/dist/cjs/src/lib/cookie/handle-http-cookie.d.ts +1 -1
- package/dist/cjs/src/lib/cookie/handle-http-cookie.js +30 -17
- 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 +18 -10
- package/dist/cjs/src/lib/cookie/handle-server-cookie.d.ts +1 -1
- package/dist/cjs/src/lib/cookie/handle-server-cookie.js +3 -5
- package/dist/cjs/src/lib/correlation-id/generate-correlation-id.d.ts +6 -0
- package/dist/cjs/src/lib/correlation-id/generate-correlation-id.js +14 -0
- package/dist/cjs/src/lib/debug/debug.d.ts +6 -0
- package/dist/cjs/src/lib/debug/debug.js +20 -3
- package/dist/cjs/src/lib/init/construct-get-browser-id-url.js +1 -0
- package/dist/cjs/src/lib/init/fetch-browser-id-from-edge-proxy.d.ts +1 -1
- package/dist/cjs/src/lib/init/fetch-browser-id-from-edge-proxy.js +8 -11
- package/dist/cjs/src/lib/init/get-guest-id.js +2 -0
- package/dist/cjs/src/lib/init/init-core-server.d.ts +7 -5
- package/dist/cjs/src/lib/init/init-core-server.js +10 -9
- package/dist/cjs/src/lib/init/init-core.d.ts +6 -4
- package/dist/cjs/src/lib/init/init-core.js +14 -13
- package/dist/cjs/src/lib/interfaces.d.ts +15 -0
- package/dist/cjs/src/lib/settings/create-settings.d.ts +1 -1
- package/dist/cjs/src/lib/settings/create-settings.js +6 -3
- package/dist/cjs/src/lib/settings/handle-get-settings-error.d.ts +1 -1
- package/dist/cjs/src/lib/settings/interfaces.d.ts +8 -11
- package/dist/cjs/src/lib/settings/validate-settings.d.ts +3 -2
- package/dist/cjs/src/lib/settings/validate-settings.js +8 -6
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/package.json +3 -4
- package/dist/esm/src/index.d.ts +8 -7
- package/dist/esm/src/index.js +6 -5
- package/dist/esm/src/lib/consts.d.ts +9 -0
- package/dist/esm/src/lib/consts.js +12 -0
- package/dist/esm/src/lib/cookie/create-cookies.d.ts +6 -0
- package/dist/esm/src/lib/cookie/create-cookies.js +24 -0
- package/dist/esm/src/lib/cookie/get-browser-id.js +1 -1
- package/dist/esm/src/lib/cookie/get-cookie-value-from-middleware-request.d.ts +11 -0
- package/dist/esm/src/lib/cookie/{get-browser-id-from-middleware-request.js → get-cookie-value-from-middleware-request.js} +4 -4
- package/dist/esm/src/lib/cookie/get-cookie-value-from-request.d.ts +9 -0
- package/dist/esm/src/lib/cookie/get-cookie-value-from-request.js +20 -0
- package/dist/esm/src/lib/cookie/get-default-cookie-attributes.d.ts +1 -1
- package/dist/esm/src/lib/cookie/get-default-cookie-attributes.js +2 -3
- package/dist/esm/src/lib/cookie/handle-http-cookie.d.ts +1 -1
- package/dist/esm/src/lib/cookie/handle-http-cookie.js +30 -17
- 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 +18 -10
- package/dist/esm/src/lib/cookie/handle-server-cookie.d.ts +1 -1
- package/dist/esm/src/lib/cookie/handle-server-cookie.js +4 -6
- package/dist/esm/src/lib/correlation-id/generate-correlation-id.d.ts +6 -0
- package/dist/esm/src/lib/correlation-id/generate-correlation-id.js +10 -0
- package/dist/esm/src/lib/debug/debug.d.ts +6 -0
- package/dist/esm/src/lib/debug/debug.js +19 -3
- package/dist/esm/src/lib/init/construct-get-browser-id-url.js +1 -0
- package/dist/esm/src/lib/init/fetch-browser-id-from-edge-proxy.d.ts +1 -1
- package/dist/esm/src/lib/init/fetch-browser-id-from-edge-proxy.js +9 -12
- package/dist/esm/src/lib/init/get-guest-id.js +3 -1
- package/dist/esm/src/lib/init/init-core-server.d.ts +7 -5
- package/dist/esm/src/lib/init/init-core-server.js +10 -9
- package/dist/esm/src/lib/init/init-core.d.ts +6 -4
- package/dist/esm/src/lib/init/init-core.js +14 -13
- package/dist/esm/src/lib/interfaces.d.ts +15 -0
- package/dist/esm/src/lib/settings/create-settings.d.ts +1 -1
- package/dist/esm/src/lib/settings/create-settings.js +6 -3
- package/dist/esm/src/lib/settings/handle-get-settings-error.d.ts +1 -1
- package/dist/esm/src/lib/settings/interfaces.d.ts +8 -11
- package/dist/esm/src/lib/settings/validate-settings.d.ts +3 -2
- package/dist/esm/src/lib/settings/validate-settings.js +8 -6
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/dist/cjs/src/lib/cookie/create-cookie.d.ts +0 -7
- package/dist/cjs/src/lib/cookie/create-cookie.js +0 -20
- package/dist/cjs/src/lib/cookie/get-browser-id-from-middleware-request.d.ts +0 -11
- package/dist/cjs/src/lib/cookie/get-browser-id-from-request.d.ts +0 -9
- package/dist/cjs/src/lib/cookie/get-browser-id-from-request.js +0 -25
- package/dist/cjs/src/lib/init/get-browser-id.d.ts +0 -5
- package/dist/cjs/src/lib/init/get-browser-id.js +0 -15
- package/dist/esm/src/lib/cookie/create-cookie.d.ts +0 -7
- package/dist/esm/src/lib/cookie/create-cookie.js +0 -16
- package/dist/esm/src/lib/cookie/get-browser-id-from-middleware-request.d.ts +0 -11
- package/dist/esm/src/lib/cookie/get-browser-id-from-request.d.ts +0 -9
- package/dist/esm/src/lib/cookie/get-browser-id-from-request.js +0 -21
- package/dist/esm/src/lib/init/get-browser-id.d.ts +0 -5
- package/dist/esm/src/lib/init/get-browser-id.js +0 -11
package/dist/cjs/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-cloudsdk/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1-rc.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/cjs/src/index.js",
|
|
6
6
|
"module": "dist/esm/src/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@sitecore-cloudsdk/utils": "^0.
|
|
19
|
+
"@sitecore-cloudsdk/utils": "^0.3.0",
|
|
20
20
|
"debug": "^4.3.4"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
"README.md"
|
|
30
30
|
],
|
|
31
31
|
"engines": {
|
|
32
|
-
"node": ">=18"
|
|
33
|
-
"npm": ">=9"
|
|
32
|
+
"node": ">=18"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
35
|
"@types/debug": "^4.1.12"
|
package/dist/cjs/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { createCookies } from './lib/cookie/create-cookies';
|
|
2
|
+
export { getCookieValueFromMiddlewareRequest } from './lib/cookie/get-cookie-value-from-middleware-request';
|
|
3
3
|
export { getDefaultCookieAttributes } from './lib/cookie/get-default-cookie-attributes';
|
|
4
4
|
export { handleHttpCookie } from './lib/cookie/handle-http-cookie';
|
|
5
5
|
export { handleNextJsMiddlewareCookie } from './lib/cookie/handle-next-js-middleware-cookie';
|
|
@@ -12,9 +12,10 @@ export { getSettings, initCore } from './lib/init/init-core';
|
|
|
12
12
|
export { getSettingsServer, initCoreServer } from './lib/init/init-core-server';
|
|
13
13
|
export { validateSettings } from './lib/settings/validate-settings';
|
|
14
14
|
export { language, pageName } from './lib/infer/infer';
|
|
15
|
-
export {
|
|
15
|
+
export { getCookieValueFromRequest } from './lib/cookie/get-cookie-value-from-request';
|
|
16
16
|
export { handleGetSettingsError } from './lib/settings/handle-get-settings-error';
|
|
17
|
-
export {
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export {
|
|
17
|
+
export { generateCorrelationId } from './lib/correlation-id/generate-correlation-id';
|
|
18
|
+
export { debug, processDebugResponse } from './lib/debug/debug';
|
|
19
|
+
export { API_VERSION, COOKIE_NAME_PREFIX, DAILY_SECONDS, DEFAULT_COOKIE_EXPIRY_DAYS, LIBRARY_VERSION, SITECORE_EDGE_URL, CORRELATION_ID_HEADER } from './lib/consts';
|
|
20
|
+
export type { EPResponse, Infer, DebugResponse } from './lib/interfaces';
|
|
21
|
+
export type { CookieSettings, Settings, BrowserSettings, ServerSettings, BasicSettings } from './lib/settings/interfaces';
|
package/dist/cjs/src/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
exports.CORRELATION_ID_HEADER = exports.SITECORE_EDGE_URL = exports.LIBRARY_VERSION = exports.DEFAULT_COOKIE_EXPIRY_DAYS = exports.DAILY_SECONDS = exports.COOKIE_NAME_PREFIX = exports.API_VERSION = exports.processDebugResponse = exports.debug = exports.generateCorrelationId = exports.handleGetSettingsError = exports.getCookieValueFromRequest = exports.pageName = exports.language = exports.validateSettings = exports.initCoreServer = exports.getSettingsServer = exports.initCore = exports.getSettings = exports.createSettings = exports.getGuestId = exports.fetchBrowserIdFromEdgeProxy = exports.getBrowserId = exports.handleServerCookie = exports.handleNextJsMiddlewareCookie = exports.handleHttpCookie = exports.getDefaultCookieAttributes = exports.getCookieValueFromMiddlewareRequest = exports.createCookies = void 0;
|
|
4
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
|
+
var create_cookies_1 = require("./lib/cookie/create-cookies");
|
|
6
|
+
Object.defineProperty(exports, "createCookies", { enumerable: true, get: function () { return create_cookies_1.createCookies; } });
|
|
7
|
+
var get_cookie_value_from_middleware_request_1 = require("./lib/cookie/get-cookie-value-from-middleware-request");
|
|
8
|
+
Object.defineProperty(exports, "getCookieValueFromMiddlewareRequest", { enumerable: true, get: function () { return get_cookie_value_from_middleware_request_1.getCookieValueFromMiddlewareRequest; } });
|
|
9
9
|
var get_default_cookie_attributes_1 = require("./lib/cookie/get-default-cookie-attributes");
|
|
10
10
|
Object.defineProperty(exports, "getDefaultCookieAttributes", { enumerable: true, get: function () { return get_default_cookie_attributes_1.getDefaultCookieAttributes; } });
|
|
11
11
|
var handle_http_cookie_1 = require("./lib/cookie/handle-http-cookie");
|
|
@@ -33,10 +33,15 @@ Object.defineProperty(exports, "validateSettings", { enumerable: true, get: func
|
|
|
33
33
|
var infer_1 = require("./lib/infer/infer");
|
|
34
34
|
Object.defineProperty(exports, "language", { enumerable: true, get: function () { return infer_1.language; } });
|
|
35
35
|
Object.defineProperty(exports, "pageName", { enumerable: true, get: function () { return infer_1.pageName; } });
|
|
36
|
-
var
|
|
37
|
-
Object.defineProperty(exports, "
|
|
36
|
+
var get_cookie_value_from_request_1 = require("./lib/cookie/get-cookie-value-from-request");
|
|
37
|
+
Object.defineProperty(exports, "getCookieValueFromRequest", { enumerable: true, get: function () { return get_cookie_value_from_request_1.getCookieValueFromRequest; } });
|
|
38
38
|
var handle_get_settings_error_1 = require("./lib/settings/handle-get-settings-error");
|
|
39
39
|
Object.defineProperty(exports, "handleGetSettingsError", { enumerable: true, get: function () { return handle_get_settings_error_1.handleGetSettingsError; } });
|
|
40
|
+
var generate_correlation_id_1 = require("./lib/correlation-id/generate-correlation-id");
|
|
41
|
+
Object.defineProperty(exports, "generateCorrelationId", { enumerable: true, get: function () { return generate_correlation_id_1.generateCorrelationId; } });
|
|
42
|
+
var debug_1 = require("./lib/debug/debug");
|
|
43
|
+
Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return debug_1.debug; } });
|
|
44
|
+
Object.defineProperty(exports, "processDebugResponse", { enumerable: true, get: function () { return debug_1.processDebugResponse; } });
|
|
40
45
|
var consts_1 = require("./lib/consts");
|
|
41
46
|
Object.defineProperty(exports, "API_VERSION", { enumerable: true, get: function () { return consts_1.API_VERSION; } });
|
|
42
47
|
Object.defineProperty(exports, "COOKIE_NAME_PREFIX", { enumerable: true, get: function () { return consts_1.COOKIE_NAME_PREFIX; } });
|
|
@@ -44,5 +49,4 @@ Object.defineProperty(exports, "DAILY_SECONDS", { enumerable: true, get: functio
|
|
|
44
49
|
Object.defineProperty(exports, "DEFAULT_COOKIE_EXPIRY_DAYS", { enumerable: true, get: function () { return consts_1.DEFAULT_COOKIE_EXPIRY_DAYS; } });
|
|
45
50
|
Object.defineProperty(exports, "LIBRARY_VERSION", { enumerable: true, get: function () { return consts_1.LIBRARY_VERSION; } });
|
|
46
51
|
Object.defineProperty(exports, "SITECORE_EDGE_URL", { enumerable: true, get: function () { return consts_1.SITECORE_EDGE_URL; } });
|
|
47
|
-
|
|
48
|
-
Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return debug_1.debug; } });
|
|
52
|
+
Object.defineProperty(exports, "CORRELATION_ID_HEADER", { enumerable: true, get: function () { return consts_1.CORRELATION_ID_HEADER; } });
|
|
@@ -4,3 +4,12 @@ export declare const DEFAULT_COOKIE_EXPIRY_DAYS = 730;
|
|
|
4
4
|
export declare const DAILY_SECONDS = 86400;
|
|
5
5
|
export declare const API_VERSION = "v1.2";
|
|
6
6
|
export declare const SITECORE_EDGE_URL = "https://edge-platform.sitecorecloud.io";
|
|
7
|
+
export declare const CORRELATION_ID_HEADER = "x-sc-correlation-id";
|
|
8
|
+
export declare enum ErrorMessages {
|
|
9
|
+
IE_0003 = "[IE-0003] Unable to set the \"sc_{SitecoreEdgeContextId}\" cookie because the browser ID could not be retrieved from the server. Make sure to set the correct values for \"sitecoreEdgeContextId\" and \"siteName\". If the issue persists, try again later or use try-catch blocks to handle this error.",
|
|
10
|
+
IE_0008 = "[IE-0008] You must first initialize the \"core\" package. Run the \"init\" function.",
|
|
11
|
+
IE_0011 = "[IE-0011] Unable to set the \"sc_{SitecoreEdgeContextId}_personalize\" cookie because the guest ID could not be retrieved from the server. Make sure to set the correct values for \"sitecoreEdgeContextId\" and \"siteName\". If the issue persists, try again later or use try-catch blocks to handle this error.",
|
|
12
|
+
IV_0001 = "[IV-0001] Incorrect value for \"sitecoreEdgeUrl\". Set the value to a valid URL string.",
|
|
13
|
+
MV_0001 = "[MV-0001] \"sitecoreEdgeContextId\" is required.",
|
|
14
|
+
MV_0002 = "[MV-0002] \"siteName\" is required."
|
|
15
|
+
}
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.SITECORE_EDGE_URL = exports.API_VERSION = exports.DAILY_SECONDS = exports.DEFAULT_COOKIE_EXPIRY_DAYS = exports.COOKIE_NAME_PREFIX = exports.LIBRARY_VERSION = void 0;
|
|
7
|
+
exports.ErrorMessages = exports.CORRELATION_ID_HEADER = exports.SITECORE_EDGE_URL = exports.API_VERSION = exports.DAILY_SECONDS = exports.DEFAULT_COOKIE_EXPIRY_DAYS = exports.COOKIE_NAME_PREFIX = exports.LIBRARY_VERSION = void 0;
|
|
8
8
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
9
9
|
const package_json_1 = __importDefault(require("../../package.json"));
|
|
10
10
|
exports.LIBRARY_VERSION = package_json_1.default.version;
|
|
@@ -13,3 +13,15 @@ exports.DEFAULT_COOKIE_EXPIRY_DAYS = 730;
|
|
|
13
13
|
exports.DAILY_SECONDS = 86400;
|
|
14
14
|
exports.API_VERSION = 'v1.2';
|
|
15
15
|
exports.SITECORE_EDGE_URL = 'https://edge-platform.sitecorecloud.io';
|
|
16
|
+
exports.CORRELATION_ID_HEADER = 'x-sc-correlation-id';
|
|
17
|
+
/* eslint-disable max-len */
|
|
18
|
+
var ErrorMessages;
|
|
19
|
+
(function (ErrorMessages) {
|
|
20
|
+
ErrorMessages["IE_0003"] = "[IE-0003] Unable to set the \"sc_{SitecoreEdgeContextId}\" cookie because the browser ID could not be retrieved from the server. Make sure to set the correct values for \"sitecoreEdgeContextId\" and \"siteName\". If the issue persists, try again later or use try-catch blocks to handle this error.";
|
|
21
|
+
ErrorMessages["IE_0008"] = "[IE-0008] You must first initialize the \"core\" package. Run the \"init\" function.";
|
|
22
|
+
ErrorMessages["IE_0011"] = "[IE-0011] Unable to set the \"sc_{SitecoreEdgeContextId}_personalize\" cookie because the guest ID could not be retrieved from the server. Make sure to set the correct values for \"sitecoreEdgeContextId\" and \"siteName\". If the issue persists, try again later or use try-catch blocks to handle this error.";
|
|
23
|
+
ErrorMessages["IV_0001"] = "[IV-0001] Incorrect value for \"sitecoreEdgeUrl\". Set the value to a valid URL string.";
|
|
24
|
+
ErrorMessages["MV_0001"] = "[MV-0001] \"sitecoreEdgeContextId\" is required.";
|
|
25
|
+
ErrorMessages["MV_0002"] = "[MV-0002] \"siteName\" is required.";
|
|
26
|
+
})(ErrorMessages || (exports.ErrorMessages = ErrorMessages = {}));
|
|
27
|
+
/* eslint-enable max-len */
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createCookies = void 0;
|
|
5
|
+
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
6
|
+
const fetch_browser_id_from_edge_proxy_1 = require("../init/fetch-browser-id-from-edge-proxy");
|
|
7
|
+
const get_default_cookie_attributes_1 = require("./get-default-cookie-attributes");
|
|
8
|
+
const get_guest_id_1 = require("../init/get-guest-id");
|
|
9
|
+
/**
|
|
10
|
+
* Creates and adds the cookie to the document
|
|
11
|
+
* @param settings - The CookieSettings settings object
|
|
12
|
+
*/
|
|
13
|
+
async function createCookies(settings) {
|
|
14
|
+
const attributes = (0, get_default_cookie_attributes_1.getDefaultCookieAttributes)(settings.cookieSettings.cookieExpiryDays, settings.cookieSettings.cookieDomain);
|
|
15
|
+
const browserIdCookie = (0, utils_1.getCookie)(window.document.cookie, settings.cookieSettings.cookieNames.browserId);
|
|
16
|
+
if (browserIdCookie) {
|
|
17
|
+
const guestIdCookie = (0, utils_1.getCookie)(window.document.cookie, settings.cookieSettings.cookieNames.guestId);
|
|
18
|
+
if (guestIdCookie)
|
|
19
|
+
return;
|
|
20
|
+
const guestId = await (0, get_guest_id_1.getGuestId)(browserIdCookie.value, settings.sitecoreEdgeContextId, settings.sitecoreEdgeUrl);
|
|
21
|
+
document.cookie = (0, utils_1.createCookieString)(settings.cookieSettings.cookieNames.guestId, guestId, attributes);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const { browserId, guestId } = await (0, fetch_browser_id_from_edge_proxy_1.fetchBrowserIdFromEdgeProxy)(settings.sitecoreEdgeUrl, settings.sitecoreEdgeContextId);
|
|
25
|
+
document.cookie = (0, utils_1.createCookieString)(settings.cookieSettings.cookieNames.browserId, browserId, attributes);
|
|
26
|
+
document.cookie = (0, utils_1.createCookieString)(settings.cookieSettings.cookieNames.guestId, guestId, attributes);
|
|
27
|
+
}
|
|
28
|
+
exports.createCookies = createCookies;
|
|
@@ -10,6 +10,6 @@ const init_core_1 = require("../init/init-core");
|
|
|
10
10
|
*/
|
|
11
11
|
function getBrowserId() {
|
|
12
12
|
const settings = (0, init_core_1.getSettings)();
|
|
13
|
-
return (0, utils_1.getCookieValueClientSide)(settings.cookieSettings.
|
|
13
|
+
return (0, utils_1.getCookieValueClientSide)(settings.cookieSettings.cookieNames.browserId);
|
|
14
14
|
}
|
|
15
15
|
exports.getBrowserId = getBrowserId;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MiddlewareRequest } from '@sitecore-cloudsdk/utils';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the cookie value from the provided Middleware Request by reading the
|
|
4
|
+
* given `cookieName` The function first checks for Next.js v12 cookie values,
|
|
5
|
+
* and if not found, it checks for Next.js v13 cookie values.
|
|
6
|
+
*
|
|
7
|
+
* @param request - The Middleware Request object.
|
|
8
|
+
* @param cookieName - The name of the cookie to retrieve.
|
|
9
|
+
* @returns The cookie value extracted from the cookie, or undefined if not found.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getCookieValueFromMiddlewareRequest(request: MiddlewareRequest, cookieName: string): string | undefined;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.getCookieValueFromMiddlewareRequest = void 0;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Extracts the cookie value from the provided Middleware Request by reading the
|
|
7
|
+
* given `cookieName` The function first checks for Next.js v12 cookie values,
|
|
8
8
|
* and if not found, it checks for Next.js v13 cookie values.
|
|
9
9
|
*
|
|
10
10
|
* @param request - The Middleware Request object.
|
|
11
11
|
* @param cookieName - The name of the cookie to retrieve.
|
|
12
|
-
* @returns The
|
|
12
|
+
* @returns The cookie value extracted from the cookie, or undefined if not found.
|
|
13
13
|
*/
|
|
14
|
-
function
|
|
14
|
+
function getCookieValueFromMiddlewareRequest(request, cookieName) {
|
|
15
15
|
const cookieValueFromRequest = request.cookies.get(cookieName);
|
|
16
16
|
// It checks nextjs v12 cookie values
|
|
17
17
|
if (typeof cookieValueFromRequest === 'string')
|
|
@@ -21,4 +21,4 @@ function getBrowserIdFromMiddlewareRequest(request, cookieName) {
|
|
|
21
21
|
return cookieValueFromRequest.value;
|
|
22
22
|
return undefined;
|
|
23
23
|
}
|
|
24
|
-
exports.
|
|
24
|
+
exports.getCookieValueFromMiddlewareRequest = getCookieValueFromMiddlewareRequest;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Request } from '@sitecore-cloudsdk/utils';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves the cookie value from the provided request object ('T'), using the specified 'cookieName'.
|
|
4
|
+
*
|
|
5
|
+
* @param request - The request object, either a Middleware Request or an HTTP Request.
|
|
6
|
+
* @param cookieName - The name of the cookie to retrieve the cookie value from.
|
|
7
|
+
* @returns The cookie value extracted from the cookie or an empty string if not found.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getCookieValueFromRequest<T extends Request>(request: T, cookieName: string): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getCookieValueFromRequest = void 0;
|
|
5
|
+
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
6
|
+
const get_cookie_value_from_middleware_request_1 = require("./get-cookie-value-from-middleware-request");
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves the cookie value from the provided request object ('T'), using the specified 'cookieName'.
|
|
9
|
+
*
|
|
10
|
+
* @param request - The request object, either a Middleware Request or an HTTP Request.
|
|
11
|
+
* @param cookieName - The name of the cookie to retrieve the cookie value from.
|
|
12
|
+
* @returns The cookie value extracted from the cookie or an empty string if not found.
|
|
13
|
+
*/
|
|
14
|
+
function getCookieValueFromRequest(request, cookieName) {
|
|
15
|
+
let cookieValue = undefined;
|
|
16
|
+
if ((0, utils_1.isNextJsMiddlewareRequest)(request))
|
|
17
|
+
cookieValue = (0, get_cookie_value_from_middleware_request_1.getCookieValueFromMiddlewareRequest)(request, cookieName);
|
|
18
|
+
else if ((0, utils_1.isHttpRequest)(request)) {
|
|
19
|
+
const cookieHeader = request.headers.cookie;
|
|
20
|
+
cookieValue = (0, utils_1.getCookieServerSide)(cookieHeader, cookieName)?.value;
|
|
21
|
+
}
|
|
22
|
+
return cookieValue ?? '';
|
|
23
|
+
}
|
|
24
|
+
exports.getCookieValueFromRequest = getCookieValueFromRequest;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { CookieProperties } from '@sitecore-cloudsdk/utils';
|
|
1
2
|
/**
|
|
2
3
|
* Gets the default Cookie Attributes
|
|
3
4
|
* @param maxAge - Set the cookie "Max-Age" attribute in days.
|
|
4
5
|
* @returns the default configuration settings for the cookie string
|
|
5
6
|
*/
|
|
6
|
-
import { CookieProperties } from '@sitecore-cloudsdk/utils';
|
|
7
7
|
export declare function getDefaultCookieAttributes(maxAge?: number, cookieDomain?: string): CookieProperties;
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultCookieAttributes = void 0;
|
|
2
4
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
|
+
const consts_1 = require("../consts");
|
|
3
6
|
/**
|
|
4
7
|
* Gets the default Cookie Attributes
|
|
5
8
|
* @param maxAge - Set the cookie "Max-Age" attribute in days.
|
|
6
9
|
* @returns the default configuration settings for the cookie string
|
|
7
10
|
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getDefaultCookieAttributes = void 0;
|
|
10
|
-
const consts_1 = require("../consts");
|
|
11
|
-
// eslint-disable-next-line max-len
|
|
12
11
|
function getDefaultCookieAttributes(maxAge = consts_1.DEFAULT_COOKIE_EXPIRY_DAYS, cookieDomain) {
|
|
13
12
|
return {
|
|
14
13
|
domain: cookieDomain,
|
|
15
14
|
maxAge: maxAge * consts_1.DAILY_SECONDS,
|
|
16
15
|
path: '/',
|
|
17
16
|
sameSite: 'None',
|
|
18
|
-
secure: true
|
|
17
|
+
secure: true
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
20
|
exports.getDefaultCookieAttributes = getDefaultCookieAttributes;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HttpRequest, HttpResponse } from '@sitecore-cloudsdk/utils';
|
|
2
|
-
import { Settings } from '../settings/interfaces';
|
|
2
|
+
import type { 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
|
*
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.handleHttpCookie = void 0;
|
|
5
|
-
const get_default_cookie_attributes_1 = require("./get-default-cookie-attributes");
|
|
6
5
|
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
7
6
|
const fetch_browser_id_from_edge_proxy_1 = require("../init/fetch-browser-id-from-edge-proxy");
|
|
7
|
+
const get_default_cookie_attributes_1 = require("./get-default-cookie-attributes");
|
|
8
|
+
const get_guest_id_1 = require("../init/get-guest-id");
|
|
8
9
|
/**
|
|
9
10
|
* Handles HTTP Cookie operations for setting the browser ID cookie in the request and response.
|
|
10
11
|
*
|
|
@@ -17,22 +18,34 @@ const fetch_browser_id_from_edge_proxy_1 = require("../init/fetch-browser-id-fro
|
|
|
17
18
|
* @throws [IE-0003] - This exception is thrown in the case getBrowserIdFromEP wasn't able to retrieve a browser id.
|
|
18
19
|
*/
|
|
19
20
|
async function handleHttpCookie(request, response, options, timeout) {
|
|
20
|
-
const {
|
|
21
|
-
const
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
cookie = (0, utils_1.getCookieServerSide)(cookieValueFromRequest, cookieName);
|
|
26
|
-
if (cookie)
|
|
27
|
-
cookieValue = cookie.value;
|
|
28
|
-
}
|
|
29
|
-
if (!cookieValue)
|
|
30
|
-
cookieValue = (await (0, fetch_browser_id_from_edge_proxy_1.fetchBrowserIdFromEdgeProxy)(options.sitecoreEdgeUrl, options.sitecoreEdgeContextId, timeout))
|
|
31
|
-
.browserId;
|
|
21
|
+
const { browserId, guestId } = options.cookieSettings.cookieNames;
|
|
22
|
+
const browserIdCookie = (0, utils_1.getCookieServerSide)(request.headers.cookie, browserId);
|
|
23
|
+
let browserIdCookieValue;
|
|
24
|
+
const guestIdCookie = (0, utils_1.getCookieServerSide)(request.headers.cookie, guestId);
|
|
25
|
+
let guestIdCookieValue;
|
|
32
26
|
const defaultCookieAttributes = (0, get_default_cookie_attributes_1.getDefaultCookieAttributes)(options.cookieSettings.cookieExpiryDays, options.cookieSettings.cookieDomain);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
if (!browserIdCookie) {
|
|
28
|
+
const cookieValues = await (0, fetch_browser_id_from_edge_proxy_1.fetchBrowserIdFromEdgeProxy)(options.sitecoreEdgeUrl, options.sitecoreEdgeContextId, timeout);
|
|
29
|
+
browserIdCookieValue = cookieValues.browserId;
|
|
30
|
+
guestIdCookieValue = cookieValues.guestId;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
browserIdCookieValue = browserIdCookie.value;
|
|
34
|
+
if (!guestIdCookie)
|
|
35
|
+
guestIdCookieValue = await (0, get_guest_id_1.getGuestId)(browserIdCookie.value, options.sitecoreEdgeContextId, options.sitecoreEdgeUrl);
|
|
36
|
+
else
|
|
37
|
+
guestIdCookieValue = guestIdCookie.value;
|
|
38
|
+
}
|
|
39
|
+
const browserIdCookieString = (0, utils_1.createCookieString)(browserId, browserIdCookieValue, defaultCookieAttributes);
|
|
40
|
+
const guestIdCookieString = (0, utils_1.createCookieString)(guestId, guestIdCookieValue, defaultCookieAttributes);
|
|
41
|
+
if (!browserIdCookie)
|
|
42
|
+
request.headers.cookie = request.headers.cookie
|
|
43
|
+
? request.headers.cookie + '; ' + browserIdCookieString
|
|
44
|
+
: browserIdCookieString;
|
|
45
|
+
if (!guestIdCookie)
|
|
46
|
+
request.headers.cookie = request.headers.cookie
|
|
47
|
+
? request.headers.cookie + '; ' + guestIdCookieString
|
|
48
|
+
: guestIdCookieString;
|
|
49
|
+
response.setHeader('Set-Cookie', [browserIdCookieString, guestIdCookieString]);
|
|
37
50
|
}
|
|
38
51
|
exports.handleHttpCookie = handleHttpCookie;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MiddlewareNextResponse, MiddlewareRequest } from '@sitecore-cloudsdk/utils';
|
|
2
|
-
import { Settings } from '../settings/interfaces';
|
|
1
|
+
import type { MiddlewareNextResponse, MiddlewareRequest } from '@sitecore-cloudsdk/utils';
|
|
2
|
+
import type { 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
|
|
@@ -10,7 +10,7 @@ import { Settings } from '../settings/interfaces';
|
|
|
10
10
|
* @param options - The settings object containing configuration options.
|
|
11
11
|
* @param defaultCookieAttributes - The default attributes for the cookie.
|
|
12
12
|
*
|
|
13
|
-
* @throws [IE-0003] - This exception is thrown
|
|
13
|
+
* @throws [IE-0003] - This exception is thrown when fetchBrowserIdFromEdgeProxy wasn't able to retrieve a browserId.
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
16
|
export declare function handleNextJsMiddlewareCookie(request: MiddlewareRequest, response: MiddlewareNextResponse, options: Settings, timeout?: number): Promise<void>;
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.handleNextJsMiddlewareCookie = void 0;
|
|
5
|
-
const get_browser_id_from_middleware_request_1 = require("./get-browser-id-from-middleware-request");
|
|
6
|
-
const get_default_cookie_attributes_1 = require("./get-default-cookie-attributes");
|
|
7
5
|
const fetch_browser_id_from_edge_proxy_1 = require("../init/fetch-browser-id-from-edge-proxy");
|
|
6
|
+
const get_cookie_value_from_middleware_request_1 = require("./get-cookie-value-from-middleware-request");
|
|
7
|
+
const get_default_cookie_attributes_1 = require("./get-default-cookie-attributes");
|
|
8
|
+
const get_guest_id_1 = require("../init/get-guest-id");
|
|
8
9
|
/**
|
|
9
10
|
* Handles the Middleware Request and sets a cookie with the provided 'cookieName' and 'cookieValue'.
|
|
10
11
|
* If 'cookieValue' is not present in the request, it fetches it using the 'fetchBrowserIdFromEdgeProxy' function
|
|
@@ -15,17 +16,24 @@ const fetch_browser_id_from_edge_proxy_1 = require("../init/fetch-browser-id-fro
|
|
|
15
16
|
* @param options - The settings object containing configuration options.
|
|
16
17
|
* @param defaultCookieAttributes - The default attributes for the cookie.
|
|
17
18
|
*
|
|
18
|
-
* @throws [IE-0003] - This exception is thrown
|
|
19
|
+
* @throws [IE-0003] - This exception is thrown when fetchBrowserIdFromEdgeProxy wasn't able to retrieve a browserId.
|
|
19
20
|
*
|
|
20
21
|
*/
|
|
21
22
|
async function handleNextJsMiddlewareCookie(request, response, options, timeout) {
|
|
22
|
-
const {
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const { browserId, guestId } = options.cookieSettings.cookieNames;
|
|
24
|
+
let browserIdCookieValue = (0, get_cookie_value_from_middleware_request_1.getCookieValueFromMiddlewareRequest)(request, browserId);
|
|
25
|
+
let guestIdCookieValue = (0, get_cookie_value_from_middleware_request_1.getCookieValueFromMiddlewareRequest)(request, guestId);
|
|
26
|
+
if (!browserIdCookieValue) {
|
|
27
|
+
const cookieValues = await (0, fetch_browser_id_from_edge_proxy_1.fetchBrowserIdFromEdgeProxy)(options.sitecoreEdgeUrl, options.sitecoreEdgeContextId, timeout);
|
|
28
|
+
browserIdCookieValue = cookieValues.browserId;
|
|
29
|
+
guestIdCookieValue = cookieValues.guestId;
|
|
30
|
+
}
|
|
31
|
+
else if (!guestIdCookieValue)
|
|
32
|
+
guestIdCookieValue = await (0, get_guest_id_1.getGuestId)(browserIdCookieValue, options.sitecoreEdgeContextId, options.sitecoreEdgeUrl);
|
|
27
33
|
const defaultCookieAttributes = (0, get_default_cookie_attributes_1.getDefaultCookieAttributes)(options.cookieSettings.cookieExpiryDays, options.cookieSettings.cookieDomain);
|
|
28
|
-
request.cookies.set(
|
|
29
|
-
|
|
34
|
+
request.cookies.set(browserId, browserIdCookieValue, defaultCookieAttributes);
|
|
35
|
+
request.cookies.set(guestId, guestIdCookieValue, defaultCookieAttributes);
|
|
36
|
+
response.cookies.set(browserId, browserIdCookieValue, defaultCookieAttributes);
|
|
37
|
+
response.cookies.set(guestId, guestIdCookieValue, defaultCookieAttributes);
|
|
30
38
|
}
|
|
31
39
|
exports.handleNextJsMiddlewareCookie = handleNextJsMiddlewareCookie;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type HttpResponse, type MiddlewareNextResponse, type Request } from '@sitecore-cloudsdk/utils';
|
|
2
2
|
/**
|
|
3
3
|
* Handles server-side cookie operations based on the provided 'request' and 'response' objects.
|
|
4
4
|
*
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.handleServerCookie = void 0;
|
|
5
5
|
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
6
6
|
const init_core_server_1 = require("../init/init-core-server");
|
|
7
|
-
const handle_next_js_middleware_cookie_1 = require("./handle-next-js-middleware-cookie");
|
|
8
7
|
const handle_http_cookie_1 = require("./handle-http-cookie");
|
|
8
|
+
const handle_next_js_middleware_cookie_1 = require("./handle-next-js-middleware-cookie");
|
|
9
9
|
/**
|
|
10
10
|
* Handles server-side cookie operations based on the provided 'request' and 'response' objects.
|
|
11
11
|
*
|
|
@@ -16,11 +16,9 @@ const handle_http_cookie_1 = require("./handle-http-cookie");
|
|
|
16
16
|
*/
|
|
17
17
|
async function handleServerCookie(request, response, timeout) {
|
|
18
18
|
const settings = (0, init_core_server_1.getSettingsServer)();
|
|
19
|
-
if ((0, utils_1.isNextJsMiddlewareRequest)(request) && (0, utils_1.isNextJsMiddlewareResponse)(response))
|
|
19
|
+
if ((0, utils_1.isNextJsMiddlewareRequest)(request) && (0, utils_1.isNextJsMiddlewareResponse)(response))
|
|
20
20
|
await (0, handle_next_js_middleware_cookie_1.handleNextJsMiddlewareCookie)(request, response, settings, timeout);
|
|
21
|
-
|
|
22
|
-
else if ((0, utils_1.isHttpRequest)(request) && (0, utils_1.isHttpResponse)(response)) {
|
|
21
|
+
else if ((0, utils_1.isHttpRequest)(request) && (0, utils_1.isHttpResponse)(response))
|
|
23
22
|
await (0, handle_http_cookie_1.handleHttpCookie)(request, response, settings, timeout);
|
|
24
|
-
}
|
|
25
23
|
}
|
|
26
24
|
exports.handleServerCookie = handleServerCookie;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.generateCorrelationId = void 0;
|
|
5
|
+
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
6
|
+
/**
|
|
7
|
+
* A function that generates a correlation id
|
|
8
|
+
*
|
|
9
|
+
* @returns A correlation id string
|
|
10
|
+
*/
|
|
11
|
+
function generateCorrelationId() {
|
|
12
|
+
return (0, utils_1.generateV4UUID)().replace(/-/g, '');
|
|
13
|
+
}
|
|
14
|
+
exports.generateCorrelationId = generateCorrelationId;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import debug from 'debug';
|
|
2
2
|
export { debug };
|
|
3
|
+
/**
|
|
4
|
+
* Extracts debug information from an HTTP response if debugging is enabled.
|
|
5
|
+
* @param response - The HTTP response object from fetch.
|
|
6
|
+
* @returns An object containing selected response details for debugging purposes.
|
|
7
|
+
*/
|
|
8
|
+
export declare function processDebugResponse(namespace: string, response: Response): object;
|
|
@@ -3,14 +3,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.debug = void 0;
|
|
7
|
-
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
6
|
+
exports.processDebugResponse = exports.debug = void 0;
|
|
8
7
|
const debug_1 = __importDefault(require("debug"));
|
|
9
8
|
exports.debug = debug_1.default;
|
|
9
|
+
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
10
10
|
if (process.env &&
|
|
11
11
|
process.env.DEBUG_MULTILINE === 'true' &&
|
|
12
12
|
debug_1.default.formatters &&
|
|
13
13
|
debug_1.default.formatters.o &&
|
|
14
|
-
debug_1.default.formatters.O)
|
|
14
|
+
debug_1.default.formatters.O)
|
|
15
15
|
debug_1.default.formatters.o = debug_1.default.formatters.O;
|
|
16
|
+
/**
|
|
17
|
+
* Extracts debug information from an HTTP response if debugging is enabled.
|
|
18
|
+
* @param response - The HTTP response object from fetch.
|
|
19
|
+
* @returns An object containing selected response details for debugging purposes.
|
|
20
|
+
*/
|
|
21
|
+
function processDebugResponse(namespace, response) {
|
|
22
|
+
let debugResponse = {};
|
|
23
|
+
if (debug_1.default.enabled(namespace))
|
|
24
|
+
debugResponse = {
|
|
25
|
+
headers: (0, utils_1.normalizeHeaders)(response.headers),
|
|
26
|
+
redirected: response.redirected,
|
|
27
|
+
status: response.status,
|
|
28
|
+
statusText: response.statusText,
|
|
29
|
+
url: response.url
|
|
30
|
+
};
|
|
31
|
+
return debugResponse;
|
|
16
32
|
}
|
|
33
|
+
exports.processDebugResponse = processDebugResponse;
|
|
@@ -10,6 +10,7 @@ const consts_1 = require("../consts");
|
|
|
10
10
|
* @returns The URL string for retrieving the browser ID and ClientKey
|
|
11
11
|
*/
|
|
12
12
|
function constructGetBrowserIdUrl(sitecoreEdgeUrl, sitecoreEdgeContextId) {
|
|
13
|
+
// eslint-disable-next-line max-len
|
|
13
14
|
return `${sitecoreEdgeUrl}/v1/events/${consts_1.API_VERSION}/browser/create.json?sitecoreContextId=${sitecoreEdgeContextId}&client_key=`;
|
|
14
15
|
}
|
|
15
16
|
exports.constructGetBrowserIdUrl = constructGetBrowserIdUrl;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.fetchBrowserIdFromEdgeProxy = void 0;
|
|
5
|
-
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
6
5
|
const consts_1 = require("../consts");
|
|
6
|
+
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
7
7
|
const construct_get_browser_id_url_1 = require("./construct-get-browser-id-url");
|
|
8
8
|
/**
|
|
9
9
|
* Gets the browser ID and Client Key from Sitecore Edge Proxy
|
|
@@ -15,30 +15,27 @@ const construct_get_browser_id_url_1 = require("./construct-get-browser-id-url")
|
|
|
15
15
|
async function fetchBrowserIdFromEdgeProxy(sitecoreEdgeUrl, sitecoreEdgeContextId, timeout) {
|
|
16
16
|
const fetchOptions = {
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
18
|
-
headers: { 'X-Library-Version': consts_1.LIBRARY_VERSION }
|
|
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
21
|
let payload;
|
|
22
|
-
if (timeout !== undefined)
|
|
22
|
+
if (timeout !== undefined)
|
|
23
23
|
payload = await (0, utils_1.fetchWithTimeout)(url, timeout, fetchOptions)
|
|
24
24
|
.then((response) => {
|
|
25
25
|
return (response && response.json()) || null;
|
|
26
26
|
})
|
|
27
27
|
.catch((err) => {
|
|
28
|
-
if (err.message.
|
|
28
|
+
if (err.message === utils_1.ErrorMessages.IV_0006 || err.message === utils_1.ErrorMessages.IE_0002)
|
|
29
29
|
throw new Error(err.message);
|
|
30
|
-
}
|
|
31
30
|
return null;
|
|
32
31
|
});
|
|
33
|
-
|
|
34
|
-
else {
|
|
32
|
+
else
|
|
35
33
|
payload = await fetch(url, fetchOptions)
|
|
36
34
|
.then((res) => res.json())
|
|
37
35
|
.catch(() => undefined);
|
|
38
|
-
}
|
|
39
36
|
if (!payload?.ref)
|
|
40
|
-
throw new Error(
|
|
41
|
-
const { ref: browserId } = payload;
|
|
42
|
-
return { browserId };
|
|
37
|
+
throw new Error(consts_1.ErrorMessages.IE_0003);
|
|
38
|
+
const { ref: browserId, customer_ref: guestId } = payload;
|
|
39
|
+
return { browserId, guestId };
|
|
43
40
|
}
|
|
44
41
|
exports.fetchBrowserIdFromEdgeProxy = fetchBrowserIdFromEdgeProxy;
|
|
@@ -20,6 +20,8 @@ async function getGuestId(browserId, sitecoreEdgeContextId, sitecoreEdgeUrl) {
|
|
|
20
20
|
const { error_msg: errorMsg, moreInfo } = data;
|
|
21
21
|
throw new Error(`${errorMsg}, for more info: ${moreInfo}`);
|
|
22
22
|
}
|
|
23
|
+
if (!data.customer.ref)
|
|
24
|
+
throw new Error(consts_1.ErrorMessages.IE_0011);
|
|
23
25
|
return data.customer.ref;
|
|
24
26
|
}
|
|
25
27
|
exports.getGuestId = getGuestId;
|