@sitecore-cloudsdk/utils 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/src/index.d.ts +23 -20
- package/dist/cjs/src/index.js +41 -16
- package/dist/cjs/src/lib/console/colors.d.ts +25 -0
- package/dist/cjs/src/lib/console/colors.js +91 -0
- package/dist/cjs/src/lib/consts.d.ts +4 -0
- package/dist/cjs/src/lib/consts.js +10 -0
- package/dist/cjs/src/lib/converters/base-64-converter.js +1 -0
- package/dist/cjs/src/lib/converters/flatten-object.d.ts +1 -1
- package/dist/cjs/src/lib/converters/flatten-object.js +1 -1
- package/dist/cjs/src/lib/converters/normalizeHeaders.d.ts +6 -0
- package/dist/cjs/src/lib/converters/normalizeHeaders.js +22 -0
- package/dist/cjs/src/lib/converters/unescape.js +2 -1
- package/dist/cjs/src/lib/cookies/create-cookie-string.d.ts +1 -1
- package/dist/cjs/src/lib/debounce/debounce.js +13 -7
- package/dist/cjs/src/lib/fetch-with-timeout.js +3 -2
- package/dist/cjs/src/lib/generators/generate-v4-uuid.d.ts +6 -0
- package/dist/cjs/src/lib/generators/generate-v4-uuid.js +13 -0
- package/dist/cjs/src/lib/interfaces.d.ts +2 -1
- package/dist/cjs/src/lib/objects/omit.js +1 -2
- package/dist/cjs/src/lib/objects/pick.js +1 -2
- package/dist/cjs/src/lib/typeguards/is-http-request.d.ts +1 -1
- package/dist/cjs/src/lib/typeguards/is-http-response.d.ts +1 -1
- package/dist/cjs/src/lib/typeguards/is-next-js-middleware-request.d.ts +1 -1
- package/dist/cjs/src/lib/typeguards/is-next-js-middleware-response.d.ts +1 -1
- package/dist/cjs/src/lib/validators/is-valid-http-url.d.ts +6 -0
- package/dist/cjs/src/lib/validators/is-valid-http-url.js +19 -0
- package/dist/cjs/src/lib/validators/is-valid-location.d.ts +12 -0
- package/dist/cjs/src/lib/validators/is-valid-location.js +16 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/index.d.ts +23 -20
- package/dist/esm/src/index.js +20 -16
- package/dist/esm/src/lib/console/colors.d.ts +25 -0
- package/dist/esm/src/lib/console/colors.js +83 -0
- package/dist/esm/src/lib/consts.d.ts +4 -0
- package/dist/esm/src/lib/consts.js +7 -0
- package/dist/esm/src/lib/converters/base-64-converter.js +1 -0
- package/dist/esm/src/lib/converters/flatten-object.d.ts +1 -1
- package/dist/esm/src/lib/converters/flatten-object.js +1 -1
- package/dist/esm/src/lib/converters/normalizeHeaders.d.ts +6 -0
- package/dist/esm/src/lib/converters/normalizeHeaders.js +18 -0
- package/dist/esm/src/lib/converters/unescape.js +2 -1
- package/dist/esm/src/lib/cookies/create-cookie-string.d.ts +1 -1
- package/dist/esm/src/lib/debounce/debounce.js +13 -7
- package/dist/esm/src/lib/fetch-with-timeout.js +3 -2
- package/dist/esm/src/lib/generators/generate-v4-uuid.d.ts +6 -0
- package/dist/esm/src/lib/generators/generate-v4-uuid.js +9 -0
- package/dist/esm/src/lib/interfaces.d.ts +2 -1
- package/dist/esm/src/lib/objects/omit.js +1 -2
- package/dist/esm/src/lib/objects/pick.js +1 -2
- package/dist/esm/src/lib/typeguards/is-http-request.d.ts +1 -1
- package/dist/esm/src/lib/typeguards/is-http-response.d.ts +1 -1
- package/dist/esm/src/lib/typeguards/is-next-js-middleware-request.d.ts +1 -1
- package/dist/esm/src/lib/typeguards/is-next-js-middleware-response.d.ts +1 -1
- package/dist/esm/src/lib/validators/is-valid-http-url.d.ts +6 -0
- package/dist/esm/src/lib/validators/is-valid-http-url.js +15 -0
- package/dist/esm/src/lib/validators/is-valid-location.d.ts +12 -0
- package/dist/esm/src/lib/validators/is-valid-location.js +12 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -3
package/dist/cjs/src/index.d.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export {
|
|
19
|
-
export
|
|
20
|
-
export
|
|
1
|
+
export { createCookieString } from './lib/cookies/create-cookie-string';
|
|
2
|
+
export { fetchWithTimeout } from './lib/fetch-with-timeout';
|
|
3
|
+
export { getCookieValueClientSide } from './lib/cookies/get-cookie-value-client-side';
|
|
4
|
+
export { isNextJsMiddlewareRequest } from './lib/typeguards/is-next-js-middleware-request';
|
|
5
|
+
export { isNextJsMiddlewareResponse } from './lib/typeguards/is-next-js-middleware-response';
|
|
6
|
+
export { isHttpRequest } from './lib/typeguards/is-http-request';
|
|
7
|
+
export { isHttpResponse } from './lib/typeguards/is-http-response';
|
|
8
|
+
export { getCookie } from './lib/cookies/get-cookie';
|
|
9
|
+
export { getCookieServerSide } from './lib/cookies/get-cookie-server-side';
|
|
10
|
+
export { cookieExists } from './lib/cookies/cookie-exists';
|
|
11
|
+
export { flattenObject } from './lib/converters/flatten-object';
|
|
12
|
+
export { isShortISODateString } from './lib/validators/is-short-iso-date-string';
|
|
13
|
+
export { isValidEmail } from './lib/validators/is-valid-email';
|
|
14
|
+
export { omit } from './lib/objects/omit';
|
|
15
|
+
export { generateV4UUID } from './lib/generators/generate-v4-uuid';
|
|
16
|
+
export * from './lib/console/colors';
|
|
17
|
+
export { normalizeHeaders } from './lib/converters/normalizeHeaders';
|
|
18
|
+
export { ErrorMessages } from './lib/consts';
|
|
19
|
+
export { isValidHttpURL } from './lib/validators/is-valid-http-url';
|
|
20
|
+
export { isValidLocation } from './lib/validators/is-valid-location';
|
|
21
|
+
export type { Request, Response, MiddlewareNextResponse, HttpResponse, MiddlewareRequest, HttpRequest, BasicTypes } from './lib/interfaces';
|
|
22
|
+
export type { Cookie, CookieProperties } from './lib/cookies/interfaces';
|
|
23
|
+
export type { NestedObject, FlattenedObject } from './lib/converters/flatten-object';
|
package/dist/cjs/src/index.js
CHANGED
|
@@ -1,32 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.omit = exports.isValidEmail = exports.isShortISODateString = exports.flattenObject = exports.cookieExists = exports.getCookieServerSide = exports.getCookie = exports.isHttpResponse = exports.isHttpRequest = exports.isNextJsMiddlewareResponse = exports.isNextJsMiddlewareRequest = exports.getCookieValueClientSide = exports.fetchWithTimeout = exports.createCookieString = void 0;
|
|
4
2
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
|
-
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.isValidLocation = exports.isValidHttpURL = exports.ErrorMessages = exports.normalizeHeaders = exports.generateV4UUID = exports.omit = exports.isValidEmail = exports.isShortISODateString = exports.flattenObject = exports.cookieExists = exports.getCookieServerSide = exports.getCookie = exports.isHttpResponse = exports.isHttpRequest = exports.isNextJsMiddlewareResponse = exports.isNextJsMiddlewareRequest = exports.getCookieValueClientSide = exports.fetchWithTimeout = exports.createCookieString = void 0;
|
|
19
|
+
var create_cookie_string_1 = require("./lib/cookies/create-cookie-string");
|
|
6
20
|
Object.defineProperty(exports, "createCookieString", { enumerable: true, get: function () { return create_cookie_string_1.createCookieString; } });
|
|
7
|
-
|
|
21
|
+
var fetch_with_timeout_1 = require("./lib/fetch-with-timeout");
|
|
8
22
|
Object.defineProperty(exports, "fetchWithTimeout", { enumerable: true, get: function () { return fetch_with_timeout_1.fetchWithTimeout; } });
|
|
9
|
-
|
|
23
|
+
var get_cookie_value_client_side_1 = require("./lib/cookies/get-cookie-value-client-side");
|
|
10
24
|
Object.defineProperty(exports, "getCookieValueClientSide", { enumerable: true, get: function () { return get_cookie_value_client_side_1.getCookieValueClientSide; } });
|
|
11
|
-
|
|
25
|
+
var is_next_js_middleware_request_1 = require("./lib/typeguards/is-next-js-middleware-request");
|
|
12
26
|
Object.defineProperty(exports, "isNextJsMiddlewareRequest", { enumerable: true, get: function () { return is_next_js_middleware_request_1.isNextJsMiddlewareRequest; } });
|
|
13
|
-
|
|
27
|
+
var is_next_js_middleware_response_1 = require("./lib/typeguards/is-next-js-middleware-response");
|
|
14
28
|
Object.defineProperty(exports, "isNextJsMiddlewareResponse", { enumerable: true, get: function () { return is_next_js_middleware_response_1.isNextJsMiddlewareResponse; } });
|
|
15
|
-
|
|
29
|
+
var is_http_request_1 = require("./lib/typeguards/is-http-request");
|
|
16
30
|
Object.defineProperty(exports, "isHttpRequest", { enumerable: true, get: function () { return is_http_request_1.isHttpRequest; } });
|
|
17
|
-
|
|
31
|
+
var is_http_response_1 = require("./lib/typeguards/is-http-response");
|
|
18
32
|
Object.defineProperty(exports, "isHttpResponse", { enumerable: true, get: function () { return is_http_response_1.isHttpResponse; } });
|
|
19
|
-
|
|
33
|
+
var get_cookie_1 = require("./lib/cookies/get-cookie");
|
|
20
34
|
Object.defineProperty(exports, "getCookie", { enumerable: true, get: function () { return get_cookie_1.getCookie; } });
|
|
21
|
-
|
|
35
|
+
var get_cookie_server_side_1 = require("./lib/cookies/get-cookie-server-side");
|
|
22
36
|
Object.defineProperty(exports, "getCookieServerSide", { enumerable: true, get: function () { return get_cookie_server_side_1.getCookieServerSide; } });
|
|
23
|
-
|
|
37
|
+
var cookie_exists_1 = require("./lib/cookies/cookie-exists");
|
|
24
38
|
Object.defineProperty(exports, "cookieExists", { enumerable: true, get: function () { return cookie_exists_1.cookieExists; } });
|
|
25
|
-
|
|
39
|
+
var flatten_object_1 = require("./lib/converters/flatten-object");
|
|
26
40
|
Object.defineProperty(exports, "flattenObject", { enumerable: true, get: function () { return flatten_object_1.flattenObject; } });
|
|
27
|
-
|
|
41
|
+
var is_short_iso_date_string_1 = require("./lib/validators/is-short-iso-date-string");
|
|
28
42
|
Object.defineProperty(exports, "isShortISODateString", { enumerable: true, get: function () { return is_short_iso_date_string_1.isShortISODateString; } });
|
|
29
|
-
|
|
43
|
+
var is_valid_email_1 = require("./lib/validators/is-valid-email");
|
|
30
44
|
Object.defineProperty(exports, "isValidEmail", { enumerable: true, get: function () { return is_valid_email_1.isValidEmail; } });
|
|
31
|
-
|
|
45
|
+
var omit_1 = require("./lib/objects/omit");
|
|
32
46
|
Object.defineProperty(exports, "omit", { enumerable: true, get: function () { return omit_1.omit; } });
|
|
47
|
+
var generate_v4_uuid_1 = require("./lib/generators/generate-v4-uuid");
|
|
48
|
+
Object.defineProperty(exports, "generateV4UUID", { enumerable: true, get: function () { return generate_v4_uuid_1.generateV4UUID; } });
|
|
49
|
+
__exportStar(require("./lib/console/colors"), exports);
|
|
50
|
+
var normalizeHeaders_1 = require("./lib/converters/normalizeHeaders");
|
|
51
|
+
Object.defineProperty(exports, "normalizeHeaders", { enumerable: true, get: function () { return normalizeHeaders_1.normalizeHeaders; } });
|
|
52
|
+
var consts_1 = require("./lib/consts");
|
|
53
|
+
Object.defineProperty(exports, "ErrorMessages", { enumerable: true, get: function () { return consts_1.ErrorMessages; } });
|
|
54
|
+
var is_valid_http_url_1 = require("./lib/validators/is-valid-http-url");
|
|
55
|
+
Object.defineProperty(exports, "isValidHttpURL", { enumerable: true, get: function () { return is_valid_http_url_1.isValidHttpURL; } });
|
|
56
|
+
var is_valid_location_1 = require("./lib/validators/is-valid-location");
|
|
57
|
+
Object.defineProperty(exports, "isValidLocation", { enumerable: true, get: function () { return is_valid_location_1.isValidLocation; } });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function changes the text to red color if in supported environment
|
|
3
|
+
* @returns A string with \\u001B[31m prefix and \\u001B[0m suffix or the original text
|
|
4
|
+
*/
|
|
5
|
+
export declare function red(text: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* A function changes the text to blue color if in supported environment
|
|
8
|
+
* @returns A string with \\u001B[34m prefix and \\u001B[0m suffix or the original text
|
|
9
|
+
*/
|
|
10
|
+
export declare function blue(text: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* A function changes the text to cyan color if in supported environment
|
|
13
|
+
* @returns A string with \\u001B[36m prefix and \\u001B[0m suffix or the original text
|
|
14
|
+
*/
|
|
15
|
+
export declare function cyan(text: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* A function changes the text to green color if in supported environment
|
|
18
|
+
* @returns A string with \\u001B[32m prefix and \\u001B[0m suffix or the original text
|
|
19
|
+
*/
|
|
20
|
+
export declare function green(text: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* A function changes the text to yellow color if in supported environment
|
|
23
|
+
* @returns A string with \\u001B[33m prefix and \\u001B[0m suffix or the original text
|
|
24
|
+
*/
|
|
25
|
+
export declare function yellow(text: string): string;
|
|
@@ -0,0 +1,91 @@
|
|
|
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.yellow = exports.green = exports.cyan = exports.blue = exports.red = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* The functions provided in the module work only in node environments an chromium based browsers.
|
|
7
|
+
* The public functions will do the required checks internally so no extra work needed outside this module.
|
|
8
|
+
* If colors are supported they will be applied and the colorized version of the text will be returned,
|
|
9
|
+
* otherwise the original text will be returned.
|
|
10
|
+
*/
|
|
11
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
12
|
+
/**
|
|
13
|
+
* The ANSI CODES for colors needed in the SDK
|
|
14
|
+
*/
|
|
15
|
+
const COLORS = {
|
|
16
|
+
BLUE: '\u001B[34m',
|
|
17
|
+
CYAN: '\u001B[36m',
|
|
18
|
+
GREEN: '\u001B[32m',
|
|
19
|
+
RED: '\u001B[31m',
|
|
20
|
+
RESET: '\u001B[0m',
|
|
21
|
+
YELLOW: '\u001B[33m'
|
|
22
|
+
};
|
|
23
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
24
|
+
/**
|
|
25
|
+
* Checks if the browser is based on chromium
|
|
26
|
+
* @returns true if the browser is based on chromium and false otherwise
|
|
27
|
+
*/
|
|
28
|
+
function isChromiumBrowser() {
|
|
29
|
+
return navigator.userAgent.includes('Chrome');
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Checks if the current running environment is browser
|
|
33
|
+
* @returns true if the environment is browser and false otherwise
|
|
34
|
+
*/
|
|
35
|
+
function isBrowserEnvironment() {
|
|
36
|
+
return typeof window !== 'undefined';
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Checks if the current running environment supports colors
|
|
40
|
+
* @returns true if the environment supports colors and false otherwise
|
|
41
|
+
*/
|
|
42
|
+
function isColorsSupported() {
|
|
43
|
+
return (isBrowserEnvironment() && isChromiumBrowser()) || !isBrowserEnvironment();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Checks and applies the color if the environment supports colors
|
|
47
|
+
* @returns the colorized string if supported or the original text
|
|
48
|
+
*/
|
|
49
|
+
function colorizeText(color, text) {
|
|
50
|
+
return isColorsSupported() ? `${color}${text}${COLORS.RESET}` : text;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A function changes the text to red color if in supported environment
|
|
54
|
+
* @returns A string with \\u001B[31m prefix and \\u001B[0m suffix or the original text
|
|
55
|
+
*/
|
|
56
|
+
function red(text) {
|
|
57
|
+
return colorizeText(COLORS.RED, text);
|
|
58
|
+
}
|
|
59
|
+
exports.red = red;
|
|
60
|
+
/**
|
|
61
|
+
* A function changes the text to blue color if in supported environment
|
|
62
|
+
* @returns A string with \\u001B[34m prefix and \\u001B[0m suffix or the original text
|
|
63
|
+
*/
|
|
64
|
+
function blue(text) {
|
|
65
|
+
return colorizeText(COLORS.BLUE, text);
|
|
66
|
+
}
|
|
67
|
+
exports.blue = blue;
|
|
68
|
+
/**
|
|
69
|
+
* A function changes the text to cyan color if in supported environment
|
|
70
|
+
* @returns A string with \\u001B[36m prefix and \\u001B[0m suffix or the original text
|
|
71
|
+
*/
|
|
72
|
+
function cyan(text) {
|
|
73
|
+
return colorizeText(COLORS.CYAN, text);
|
|
74
|
+
}
|
|
75
|
+
exports.cyan = cyan;
|
|
76
|
+
/**
|
|
77
|
+
* A function changes the text to green color if in supported environment
|
|
78
|
+
* @returns A string with \\u001B[32m prefix and \\u001B[0m suffix or the original text
|
|
79
|
+
*/
|
|
80
|
+
function green(text) {
|
|
81
|
+
return colorizeText(COLORS.GREEN, text);
|
|
82
|
+
}
|
|
83
|
+
exports.green = green;
|
|
84
|
+
/**
|
|
85
|
+
* A function changes the text to yellow color if in supported environment
|
|
86
|
+
* @returns A string with \\u001B[33m prefix and \\u001B[0m suffix or the original text
|
|
87
|
+
*/
|
|
88
|
+
function yellow(text) {
|
|
89
|
+
return colorizeText(COLORS.YELLOW, text);
|
|
90
|
+
}
|
|
91
|
+
exports.yellow = yellow;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
3
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.ErrorMessages = void 0;
|
|
6
|
+
var ErrorMessages;
|
|
7
|
+
(function (ErrorMessages) {
|
|
8
|
+
ErrorMessages["IV_0006"] = "[IV-0006] Incorrect value for \"timeout\". Set the value to an integer greater than or equal to 0.";
|
|
9
|
+
ErrorMessages["IE_0002"] = "[IE-0002] Timeout exceeded. The server did not respond within the allotted time.";
|
|
10
|
+
})(ErrorMessages || (exports.ErrorMessages = ErrorMessages = {}));
|
|
@@ -7,6 +7,7 @@ exports.convertToBase64 = void 0;
|
|
|
7
7
|
* @param input - The string or object to be converted
|
|
8
8
|
* @returns A base64 string
|
|
9
9
|
*/
|
|
10
|
+
//
|
|
10
11
|
function convertToBase64(input) {
|
|
11
12
|
const data = typeof input === 'string' ? input : JSON.stringify(input);
|
|
12
13
|
const stringFormat = 'base64';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts headers from various formats into a uniform key-value pair object.
|
|
3
|
+
* @param incomingHeaders - Incoming headers in various formats such as Headers object or plain object.
|
|
4
|
+
* @returns A record object containing headers as key-value pairs.
|
|
5
|
+
*/
|
|
6
|
+
export declare function normalizeHeaders(incomingHeaders?: HeadersInit): Record<string, string | string[]>;
|
|
@@ -0,0 +1,22 @@
|
|
|
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.normalizeHeaders = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Converts headers from various formats into a uniform key-value pair object.
|
|
7
|
+
* @param incomingHeaders - Incoming headers in various formats such as Headers object or plain object.
|
|
8
|
+
* @returns A record object containing headers as key-value pairs.
|
|
9
|
+
*/
|
|
10
|
+
function normalizeHeaders(incomingHeaders = {}) {
|
|
11
|
+
const headers = {};
|
|
12
|
+
if (typeof incomingHeaders.forEach === 'function')
|
|
13
|
+
incomingHeaders.forEach((value, key) => {
|
|
14
|
+
headers[key] = value;
|
|
15
|
+
});
|
|
16
|
+
else
|
|
17
|
+
Object.entries(incomingHeaders).forEach(([key, value]) => {
|
|
18
|
+
headers[key] = value;
|
|
19
|
+
});
|
|
20
|
+
return headers;
|
|
21
|
+
}
|
|
22
|
+
exports.normalizeHeaders = normalizeHeaders;
|
|
@@ -8,8 +8,9 @@ const htmlUnescape = {
|
|
|
8
8
|
'&': '&',
|
|
9
9
|
'>': '>',
|
|
10
10
|
'<': '<',
|
|
11
|
-
'"': '"'
|
|
11
|
+
'"': '"'
|
|
12
12
|
};
|
|
13
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
13
14
|
/** Used to match HTML entities and HTML characters. */
|
|
14
15
|
const reEscapedHtml = /&(?:amp|lt|gt|quot|#(0+)?39);/g;
|
|
15
16
|
const reHasEscapedHtml = new RegExp(reEscapedHtml.source);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
3
|
-
/* eslint-disable
|
|
3
|
+
/* eslint-disable tsdoc/syntax, @typescript-eslint/no-explicit-any */
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.debounce = void 0;
|
|
6
6
|
/**
|
|
@@ -20,12 +20,10 @@ function debounce(fn, wait, opts = {}) {
|
|
|
20
20
|
let timer;
|
|
21
21
|
const pendingArgs = [];
|
|
22
22
|
const debounced = (...args) => {
|
|
23
|
-
if (deferred && timer)
|
|
23
|
+
if (deferred && timer)
|
|
24
24
|
clearTimeout(timer);
|
|
25
|
-
|
|
26
|
-
else {
|
|
25
|
+
else
|
|
27
26
|
deferred = defer();
|
|
28
|
-
}
|
|
29
27
|
pendingArgs.push(args);
|
|
30
28
|
timer = setTimeout(() => {
|
|
31
29
|
flush();
|
|
@@ -39,7 +37,9 @@ function debounce(fn, wait, opts = {}) {
|
|
|
39
37
|
const flush = () => {
|
|
40
38
|
const thisDeferred = deferred;
|
|
41
39
|
clearTimeout(timer);
|
|
42
|
-
Promise.resolve(opts.accumulate ? fn(...pendingArgs) : fn(...pendingArgs[pendingArgs.length - 1])
|
|
40
|
+
Promise.resolve(opts.accumulate ? fn(...pendingArgs) : fn(...pendingArgs[pendingArgs.length - 1])
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
42
|
+
).then(thisDeferred.resolve, thisDeferred.reject);
|
|
43
43
|
pendingArgs.length = 0;
|
|
44
44
|
deferred = undefined;
|
|
45
45
|
};
|
|
@@ -53,11 +53,17 @@ exports.debounce = debounce;
|
|
|
53
53
|
* @returns The deferred object.
|
|
54
54
|
*/
|
|
55
55
|
function defer() {
|
|
56
|
+
// eslint-disable-next-line no-empty-function, @typescript-eslint/no-empty-function
|
|
56
57
|
let resolve = () => { };
|
|
58
|
+
// eslint-disable-next-line no-empty-function, @typescript-eslint/no-empty-function
|
|
57
59
|
let reject = () => { };
|
|
58
60
|
const promise = new Promise((res, rej) => {
|
|
59
61
|
resolve = res;
|
|
60
62
|
reject = rej;
|
|
61
63
|
});
|
|
62
|
-
return {
|
|
64
|
+
return {
|
|
65
|
+
promise,
|
|
66
|
+
reject,
|
|
67
|
+
resolve
|
|
68
|
+
};
|
|
63
69
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
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.fetchWithTimeout = void 0;
|
|
5
|
+
const consts_1 = require("./consts");
|
|
5
6
|
/**
|
|
6
7
|
* Fetches data from the specified URL within the given timeout period.
|
|
7
8
|
*
|
|
@@ -13,7 +14,7 @@ exports.fetchWithTimeout = void 0;
|
|
|
13
14
|
*/
|
|
14
15
|
async function fetchWithTimeout(url, timeout, fetchOptions) {
|
|
15
16
|
if (!Number.isInteger(timeout) || timeout < 0)
|
|
16
|
-
throw new Error(
|
|
17
|
+
throw new Error(consts_1.ErrorMessages.IV_0006);
|
|
17
18
|
const abortController = new AbortController();
|
|
18
19
|
const signal = abortController.signal;
|
|
19
20
|
const timeoutHandler = setTimeout(() => {
|
|
@@ -26,7 +27,7 @@ async function fetchWithTimeout(url, timeout, fetchOptions) {
|
|
|
26
27
|
})
|
|
27
28
|
.catch((error) => {
|
|
28
29
|
if (error.name === 'AbortError')
|
|
29
|
-
throw new Error(
|
|
30
|
+
throw new Error(consts_1.ErrorMessages.IE_0002);
|
|
30
31
|
return null;
|
|
31
32
|
});
|
|
32
33
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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.generateV4UUID = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* A functions that generates and returns a v4 UUID string
|
|
7
|
+
*
|
|
8
|
+
* @returns Returns a v4 UUID string
|
|
9
|
+
*/
|
|
10
|
+
function generateV4UUID() {
|
|
11
|
+
return globalThis.crypto.randomUUID();
|
|
12
|
+
}
|
|
13
|
+
exports.generateV4UUID = generateV4UUID;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Cookie } from './cookies/interfaces';
|
|
1
|
+
import type { Cookie } from './cookies/interfaces';
|
|
2
2
|
/**
|
|
3
3
|
* A reusable type that accepts only basic types and arrays of those
|
|
4
4
|
*/
|
|
@@ -52,3 +52,4 @@ export interface MiddlewareNextResponse {
|
|
|
52
52
|
set: ((key: string, value: unknown, options?: any) => any) | ((...args: [key: string, value: string] | [options: Cookie]) => any);
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
+
export type Response = HttpResponse | MiddlewareNextResponse;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HttpResponse, MiddlewareNextResponse } from '../interfaces';
|
|
1
|
+
import type { HttpResponse, MiddlewareNextResponse } from '../interfaces';
|
|
2
2
|
/**
|
|
3
3
|
* Checks if the given 'response' object is a valid HTTP Response
|
|
4
4
|
* by verifying the presence of necessary properties.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HttpResponse, MiddlewareNextResponse } from '../interfaces';
|
|
1
|
+
import type { HttpResponse, MiddlewareNextResponse } from '../interfaces';
|
|
2
2
|
/**
|
|
3
3
|
* Checks if the given 'response' object is a valid MiddlewareNextResponse Response
|
|
4
4
|
* by verifying the presence of necessary properties.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidHttpURL = void 0;
|
|
4
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param url - the url string to be validated
|
|
8
|
+
* @returns - a boolean value depending on whether the url value passed is valid
|
|
9
|
+
*/
|
|
10
|
+
function isValidHttpURL(url) {
|
|
11
|
+
try {
|
|
12
|
+
const givenURL = new URL(url);
|
|
13
|
+
return ['http:', 'https:'].includes(givenURL.protocol);
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.isValidHttpURL = isValidHttpURL;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the provided location object has valid latitude and longitude values
|
|
3
|
+
* @param location - The location object
|
|
4
|
+
* @returns - An object containing booleans per attribute
|
|
5
|
+
*/
|
|
6
|
+
export declare function isValidLocation(location: {
|
|
7
|
+
latitude: number;
|
|
8
|
+
longitude: number;
|
|
9
|
+
}): {
|
|
10
|
+
latitude: boolean;
|
|
11
|
+
longitude: boolean;
|
|
12
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
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.isValidLocation = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Checks if the provided location object has valid latitude and longitude values
|
|
7
|
+
* @param location - The location object
|
|
8
|
+
* @returns - An object containing booleans per attribute
|
|
9
|
+
*/
|
|
10
|
+
function isValidLocation(location) {
|
|
11
|
+
return {
|
|
12
|
+
latitude: !(location.latitude > 90 || location.latitude < -90),
|
|
13
|
+
longitude: !(location.longitude > 180 || location.longitude < -180)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.isValidLocation = isValidLocation;
|