@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.
Files changed (59) hide show
  1. package/dist/cjs/src/index.d.ts +23 -20
  2. package/dist/cjs/src/index.js +41 -16
  3. package/dist/cjs/src/lib/console/colors.d.ts +25 -0
  4. package/dist/cjs/src/lib/console/colors.js +91 -0
  5. package/dist/cjs/src/lib/consts.d.ts +4 -0
  6. package/dist/cjs/src/lib/consts.js +10 -0
  7. package/dist/cjs/src/lib/converters/base-64-converter.js +1 -0
  8. package/dist/cjs/src/lib/converters/flatten-object.d.ts +1 -1
  9. package/dist/cjs/src/lib/converters/flatten-object.js +1 -1
  10. package/dist/cjs/src/lib/converters/normalizeHeaders.d.ts +6 -0
  11. package/dist/cjs/src/lib/converters/normalizeHeaders.js +22 -0
  12. package/dist/cjs/src/lib/converters/unescape.js +2 -1
  13. package/dist/cjs/src/lib/cookies/create-cookie-string.d.ts +1 -1
  14. package/dist/cjs/src/lib/debounce/debounce.js +13 -7
  15. package/dist/cjs/src/lib/fetch-with-timeout.js +3 -2
  16. package/dist/cjs/src/lib/generators/generate-v4-uuid.d.ts +6 -0
  17. package/dist/cjs/src/lib/generators/generate-v4-uuid.js +13 -0
  18. package/dist/cjs/src/lib/interfaces.d.ts +2 -1
  19. package/dist/cjs/src/lib/objects/omit.js +1 -2
  20. package/dist/cjs/src/lib/objects/pick.js +1 -2
  21. package/dist/cjs/src/lib/typeguards/is-http-request.d.ts +1 -1
  22. package/dist/cjs/src/lib/typeguards/is-http-response.d.ts +1 -1
  23. package/dist/cjs/src/lib/typeguards/is-next-js-middleware-request.d.ts +1 -1
  24. package/dist/cjs/src/lib/typeguards/is-next-js-middleware-response.d.ts +1 -1
  25. package/dist/cjs/src/lib/validators/is-valid-http-url.d.ts +6 -0
  26. package/dist/cjs/src/lib/validators/is-valid-http-url.js +19 -0
  27. package/dist/cjs/src/lib/validators/is-valid-location.d.ts +12 -0
  28. package/dist/cjs/src/lib/validators/is-valid-location.js +16 -0
  29. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  30. package/dist/esm/src/index.d.ts +23 -20
  31. package/dist/esm/src/index.js +20 -16
  32. package/dist/esm/src/lib/console/colors.d.ts +25 -0
  33. package/dist/esm/src/lib/console/colors.js +83 -0
  34. package/dist/esm/src/lib/consts.d.ts +4 -0
  35. package/dist/esm/src/lib/consts.js +7 -0
  36. package/dist/esm/src/lib/converters/base-64-converter.js +1 -0
  37. package/dist/esm/src/lib/converters/flatten-object.d.ts +1 -1
  38. package/dist/esm/src/lib/converters/flatten-object.js +1 -1
  39. package/dist/esm/src/lib/converters/normalizeHeaders.d.ts +6 -0
  40. package/dist/esm/src/lib/converters/normalizeHeaders.js +18 -0
  41. package/dist/esm/src/lib/converters/unescape.js +2 -1
  42. package/dist/esm/src/lib/cookies/create-cookie-string.d.ts +1 -1
  43. package/dist/esm/src/lib/debounce/debounce.js +13 -7
  44. package/dist/esm/src/lib/fetch-with-timeout.js +3 -2
  45. package/dist/esm/src/lib/generators/generate-v4-uuid.d.ts +6 -0
  46. package/dist/esm/src/lib/generators/generate-v4-uuid.js +9 -0
  47. package/dist/esm/src/lib/interfaces.d.ts +2 -1
  48. package/dist/esm/src/lib/objects/omit.js +1 -2
  49. package/dist/esm/src/lib/objects/pick.js +1 -2
  50. package/dist/esm/src/lib/typeguards/is-http-request.d.ts +1 -1
  51. package/dist/esm/src/lib/typeguards/is-http-response.d.ts +1 -1
  52. package/dist/esm/src/lib/typeguards/is-next-js-middleware-request.d.ts +1 -1
  53. package/dist/esm/src/lib/typeguards/is-next-js-middleware-response.d.ts +1 -1
  54. package/dist/esm/src/lib/validators/is-valid-http-url.d.ts +6 -0
  55. package/dist/esm/src/lib/validators/is-valid-http-url.js +15 -0
  56. package/dist/esm/src/lib/validators/is-valid-location.d.ts +12 -0
  57. package/dist/esm/src/lib/validators/is-valid-location.js +12 -0
  58. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  59. package/package.json +2 -3
@@ -1,20 +1,23 @@
1
- import { createCookieString } from './lib/cookies/create-cookie-string';
2
- import { CookieProperties } from './lib/cookies/interfaces';
3
- import { fetchWithTimeout } from './lib/fetch-with-timeout';
4
- import { getCookieValueClientSide } from './lib/cookies/get-cookie-value-client-side';
5
- import { isNextJsMiddlewareRequest } from './lib/typeguards/is-next-js-middleware-request';
6
- import { isNextJsMiddlewareResponse } from './lib/typeguards/is-next-js-middleware-response';
7
- import { isHttpRequest } from './lib/typeguards/is-http-request';
8
- import { isHttpResponse } from './lib/typeguards/is-http-response';
9
- import { getCookie } from './lib/cookies/get-cookie';
10
- import { getCookieServerSide } from './lib/cookies/get-cookie-server-side';
11
- import { cookieExists } from './lib/cookies/cookie-exists';
12
- import { flattenObject, NestedObject, FlattenedObject } from './lib/converters/flatten-object';
13
- import { isShortISODateString } from './lib/validators/is-short-iso-date-string';
14
- import { isValidEmail } from './lib/validators/is-valid-email';
15
- import { omit } from './lib/objects/omit';
16
- import type { Request, MiddlewareNextResponse, HttpResponse, MiddlewareRequest, HttpRequest, BasicTypes } from './lib/interfaces';
17
- import type { Cookie } from './lib/cookies/interfaces';
18
- export { createCookieString, fetchWithTimeout, getCookieValueClientSide, isNextJsMiddlewareRequest, isNextJsMiddlewareResponse, isHttpRequest, isHttpResponse, getCookie, getCookieServerSide, cookieExists, flattenObject, isShortISODateString, isValidEmail, omit, };
19
- export type { NestedObject, Request, MiddlewareNextResponse, BasicTypes, HttpResponse, HttpRequest, MiddlewareRequest, FlattenedObject, };
20
- export type { Cookie, CookieProperties };
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';
@@ -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
- const create_cookie_string_1 = require("./lib/cookies/create-cookie-string");
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
- const fetch_with_timeout_1 = require("./lib/fetch-with-timeout");
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
- const get_cookie_value_client_side_1 = require("./lib/cookies/get-cookie-value-client-side");
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
- const is_next_js_middleware_request_1 = require("./lib/typeguards/is-next-js-middleware-request");
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
- const is_next_js_middleware_response_1 = require("./lib/typeguards/is-next-js-middleware-response");
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
- const is_http_request_1 = require("./lib/typeguards/is-http-request");
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
- const is_http_response_1 = require("./lib/typeguards/is-http-response");
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
- const get_cookie_1 = require("./lib/cookies/get-cookie");
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
- const get_cookie_server_side_1 = require("./lib/cookies/get-cookie-server-side");
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
- const cookie_exists_1 = require("./lib/cookies/cookie-exists");
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
- const flatten_object_1 = require("./lib/converters/flatten-object");
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
- const is_short_iso_date_string_1 = require("./lib/validators/is-short-iso-date-string");
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
- const is_valid_email_1 = require("./lib/validators/is-valid-email");
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
- const omit_1 = require("./lib/objects/omit");
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,4 @@
1
+ export declare enum ErrorMessages {
2
+ IV_0006 = "[IV-0006] Incorrect value for \"timeout\". Set the value to an integer greater than or equal to 0.",
3
+ IE_0002 = "[IE-0002] Timeout exceeded. The server did not respond within the allotted time."
4
+ }
@@ -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';
@@ -1,4 +1,4 @@
1
- import { BasicTypes } from '../interfaces';
1
+ import type { BasicTypes } from '../interfaces';
2
2
  /**
3
3
  * A function that flattens an object, by combining the keys with an "_".
4
4
  * @param data - An object that has the required data to perform the flattening
@@ -25,7 +25,7 @@ function flattenObject(data) {
25
25
  flattenObject({
26
26
  currentKey: `${currentKey ? `${currentKey}_${key}` : key}`,
27
27
  newObject,
28
- object: value,
28
+ object: value
29
29
  });
30
30
  else
31
31
  newObject[currentKey ? `${currentKey}_${key}` : key] = value;
@@ -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
  '&amp;': '&',
9
9
  '&gt;': '>',
10
10
  '&lt;': '<',
11
- '&quot;': '"',
11
+ '&quot;': '"'
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,4 +1,4 @@
1
- import { CookieProperties } from './interfaces';
1
+ import type { CookieProperties } from './interfaces';
2
2
  /**
3
3
  * Creates the cookie string with the respectively cookie attributes
4
4
  * @param name - name of the cookie
@@ -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 @typescript-eslint/no-empty-function, tsdoc/syntax, sort-keys, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
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])).then(thisDeferred.resolve, thisDeferred.reject);
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 { promise, resolve, reject };
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('[IV-0006] Incorrect value for the timeout parameter. Set the value to an integer greater than or equal to 0.');
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('[IE-0002] Timeout exceeded. The server did not respond within the allotted time.');
30
+ throw new Error(consts_1.ErrorMessages.IE_0002);
30
31
  return null;
31
32
  });
32
33
  }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A functions that generates and returns a v4 UUID string
3
+ *
4
+ * @returns Returns a v4 UUID string
5
+ */
6
+ export declare function generateV4UUID(): string;
@@ -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;
@@ -11,9 +11,8 @@ exports.omit = void 0;
11
11
  */
12
12
  function omit(data, keys) {
13
13
  const result = { ...data };
14
- for (const key of keys) {
14
+ for (const key of keys)
15
15
  delete result[key];
16
- }
17
16
  return result;
18
17
  }
19
18
  exports.omit = omit;
@@ -11,9 +11,8 @@ exports.pick = void 0;
11
11
  */
12
12
  function pick(data, keys) {
13
13
  const result = {};
14
- for (const key of keys) {
14
+ for (const key of keys)
15
15
  result[key] = data[key];
16
- }
17
16
  return result;
18
17
  }
19
18
  exports.pick = pick;
@@ -1,4 +1,4 @@
1
- import { HttpRequest, Request } from '../interfaces';
1
+ import type { HttpRequest, Request } from '../interfaces';
2
2
  /**
3
3
  * Checks if the given 'request' object is a valid HTTP Request
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 HTTP Response
4
4
  * by verifying the presence of necessary properties.
@@ -1,4 +1,4 @@
1
- import { MiddlewareRequest, Request } from '../interfaces';
1
+ import type { MiddlewareRequest, Request } from '../interfaces';
2
2
  /**
3
3
  * Checks if the given 'request' object is a valid Middleware Request
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,6 @@
1
+ /**
2
+ *
3
+ * @param url - the url string to be validated
4
+ * @returns - a boolean value depending on whether the url value passed is valid
5
+ */
6
+ export declare function isValidHttpURL(url: string): boolean;
@@ -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;