@sitecore-jss/sitecore-jss 21.10.0 → 21.10.1
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/utils/index.js +6 -1
- package/dist/cjs/utils/utils.js +80 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/utils.js +74 -0
- package/package.json +2 -2
- package/types/utils/index.d.ts +1 -1
- package/types/utils/utils.d.ts +34 -0
package/dist/cjs/utils/index.js
CHANGED
|
@@ -3,13 +3,18 @@ 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.mapButtonToCommand = exports.DefaultEditFrameButtonIds = exports.DefaultEditFrameButtons = exports.DefaultEditFrameButton = exports.handleEditorAnchors = exports.resetEditorChromes = exports.isEditorActive = exports.HorizonEditor = exports.ExperienceEditor = exports.tryParseEnvValue = exports.isTimeoutError = exports.isAbsoluteUrl = exports.resolveUrl = exports.isServer = void 0;
|
|
6
|
+
exports.mapButtonToCommand = exports.DefaultEditFrameButtonIds = exports.DefaultEditFrameButtons = exports.DefaultEditFrameButton = exports.handleEditorAnchors = exports.resetEditorChromes = exports.isEditorActive = exports.HorizonEditor = exports.ExperienceEditor = exports.tryParseEnvValue = exports.getAllowedOriginsFromEnv = exports.mergeURLSearchParams = exports.escapeNonSpecialQuestionMarks = exports.areURLSearchParamsEqual = exports.isRegexOrUrl = exports.isTimeoutError = exports.isAbsoluteUrl = exports.resolveUrl = exports.isServer = void 0;
|
|
7
7
|
var is_server_1 = require("./is-server");
|
|
8
8
|
Object.defineProperty(exports, "isServer", { enumerable: true, get: function () { return __importDefault(is_server_1).default; } });
|
|
9
9
|
var utils_1 = require("./utils");
|
|
10
10
|
Object.defineProperty(exports, "resolveUrl", { enumerable: true, get: function () { return utils_1.resolveUrl; } });
|
|
11
11
|
Object.defineProperty(exports, "isAbsoluteUrl", { enumerable: true, get: function () { return utils_1.isAbsoluteUrl; } });
|
|
12
12
|
Object.defineProperty(exports, "isTimeoutError", { enumerable: true, get: function () { return utils_1.isTimeoutError; } });
|
|
13
|
+
Object.defineProperty(exports, "isRegexOrUrl", { enumerable: true, get: function () { return utils_1.isRegexOrUrl; } });
|
|
14
|
+
Object.defineProperty(exports, "areURLSearchParamsEqual", { enumerable: true, get: function () { return utils_1.areURLSearchParamsEqual; } });
|
|
15
|
+
Object.defineProperty(exports, "escapeNonSpecialQuestionMarks", { enumerable: true, get: function () { return utils_1.escapeNonSpecialQuestionMarks; } });
|
|
16
|
+
Object.defineProperty(exports, "mergeURLSearchParams", { enumerable: true, get: function () { return utils_1.mergeURLSearchParams; } });
|
|
17
|
+
Object.defineProperty(exports, "getAllowedOriginsFromEnv", { enumerable: true, get: function () { return utils_1.getAllowedOriginsFromEnv; } });
|
|
13
18
|
var env_1 = require("./env");
|
|
14
19
|
Object.defineProperty(exports, "tryParseEnvValue", { enumerable: true, get: function () { return env_1.tryParseEnvValue; } });
|
|
15
20
|
var editing_1 = require("./editing");
|
package/dist/cjs/utils/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.isTimeoutError = exports.isAbsoluteUrl = exports.resolveUrl = void 0;
|
|
6
|
+
exports.mergeURLSearchParams = exports.escapeNonSpecialQuestionMarks = exports.areURLSearchParamsEqual = exports.isRegexOrUrl = exports.getAllowedOriginsFromEnv = exports.isTimeoutError = exports.isAbsoluteUrl = exports.resolveUrl = void 0;
|
|
7
7
|
const is_server_1 = __importDefault(require("./is-server"));
|
|
8
8
|
/**
|
|
9
9
|
* note: encodeURIComponent is available via browser (window) or natively in node.js
|
|
@@ -72,3 +72,82 @@ const isTimeoutError = (error) => {
|
|
|
72
72
|
error.name === 'AbortError');
|
|
73
73
|
};
|
|
74
74
|
exports.isTimeoutError = isTimeoutError;
|
|
75
|
+
/**
|
|
76
|
+
* Gets allowed origins from JSS_ALLOWED_ORIGINS env variable
|
|
77
|
+
* @returns {string[]} list of allowed origins from JSS_ALLOWED_ORIGINS env variable
|
|
78
|
+
*/
|
|
79
|
+
const getAllowedOriginsFromEnv = () => process.env.JSS_ALLOWED_ORIGINS
|
|
80
|
+
? process.env.JSS_ALLOWED_ORIGINS.replace(' ', '').split(',')
|
|
81
|
+
: [];
|
|
82
|
+
exports.getAllowedOriginsFromEnv = getAllowedOriginsFromEnv;
|
|
83
|
+
/**
|
|
84
|
+
* Determines whether the given input is a regular expression or resembles a URL.
|
|
85
|
+
* @param {string} input - The input string to evaluate.
|
|
86
|
+
* @returns {'regex' | 'url'} - Returns 'url' if the input looks like a URL, otherwise 'regex'.
|
|
87
|
+
*/
|
|
88
|
+
const isRegexOrUrl = (input) => {
|
|
89
|
+
// Remove the trailing slash.
|
|
90
|
+
input = input.slice(0, -1);
|
|
91
|
+
// Check if the string resembles a URL.
|
|
92
|
+
const isUrlLike = /^\/[a-zA-Z0-9\-\/]+(\?([a-zA-Z0-9\-_]+=[a-zA-Z0-9\-_]+)(&[a-zA-Z0-9\-_]+=[a-zA-Z0-9\-_]+)*)?$/.test(input);
|
|
93
|
+
if (isUrlLike) {
|
|
94
|
+
return 'url';
|
|
95
|
+
}
|
|
96
|
+
// If it doesn't resemble a URL, it's likely a regular expression.
|
|
97
|
+
return 'regex';
|
|
98
|
+
};
|
|
99
|
+
exports.isRegexOrUrl = isRegexOrUrl;
|
|
100
|
+
/**
|
|
101
|
+
* Compares two URLSearchParams objects to determine if they are equal.
|
|
102
|
+
* @param {URLSearchParams} params1 - The first set of URL search parameters.
|
|
103
|
+
* @param {URLSearchParams} params2 - The second set of URL search parameters.
|
|
104
|
+
* @returns {boolean} - Returns true if the parameters are equal, otherwise false.
|
|
105
|
+
*/
|
|
106
|
+
const areURLSearchParamsEqual = (params1, params2) => {
|
|
107
|
+
// Generates a sorted string representation of URL search parameters.
|
|
108
|
+
const getSortedParamsString = (params) => {
|
|
109
|
+
return [...params.entries()]
|
|
110
|
+
.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
|
|
111
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
112
|
+
.join('&');
|
|
113
|
+
};
|
|
114
|
+
// Compare the sorted strings of both parameter sets.
|
|
115
|
+
return getSortedParamsString(params1) === getSortedParamsString(params2);
|
|
116
|
+
};
|
|
117
|
+
exports.areURLSearchParamsEqual = areURLSearchParamsEqual;
|
|
118
|
+
/**
|
|
119
|
+
* Escapes non-special "?" characters in a string or regex.
|
|
120
|
+
* - For regular strings, it escapes all unescaped "?" characters by adding a backslash (`\`).
|
|
121
|
+
* - For regex patterns (strings enclosed in `/.../`), it analyzes each "?" to determine if it has special meaning
|
|
122
|
+
* (e.g., `?` in `(abc)?`, `.*?`, `(?!...)`) or is just a literal character. Only literal "?" characters are escaped.
|
|
123
|
+
* @param {string} input - The input string or regex pattern.
|
|
124
|
+
* @returns {string} - The modified string or regex with non-special "?" characters escaped.
|
|
125
|
+
*/
|
|
126
|
+
const escapeNonSpecialQuestionMarks = (input) => {
|
|
127
|
+
// If the input is already a regex pattern (starts with ^ or ends with $), return it unchanged
|
|
128
|
+
if (input.startsWith('^') || input.endsWith('$')) {
|
|
129
|
+
return input;
|
|
130
|
+
}
|
|
131
|
+
// For non-regex strings, escape literal "?" characters
|
|
132
|
+
return input.replace(/\?/g, '\\?');
|
|
133
|
+
};
|
|
134
|
+
exports.escapeNonSpecialQuestionMarks = escapeNonSpecialQuestionMarks;
|
|
135
|
+
/**
|
|
136
|
+
* Merges two URLSearchParams objects. If both objects contain the same key, the value from the second object overrides the first.
|
|
137
|
+
* @param {URLSearchParams} params1 - The first set of URL search parameters.
|
|
138
|
+
* @param {URLSearchParams} params2 - The second set of URL search parameters.
|
|
139
|
+
* @returns {string} - A string representation of the merged URL search parameters.
|
|
140
|
+
*/
|
|
141
|
+
const mergeURLSearchParams = (params1, params2) => {
|
|
142
|
+
const merged = new URLSearchParams();
|
|
143
|
+
// Add all keys and values from the first object.
|
|
144
|
+
for (const [key, value] of params1.entries()) {
|
|
145
|
+
merged.set(key, value);
|
|
146
|
+
}
|
|
147
|
+
// Add all keys and values from the second object, replacing existing ones.
|
|
148
|
+
for (const [key, value] of params2.entries()) {
|
|
149
|
+
merged.set(key, value);
|
|
150
|
+
}
|
|
151
|
+
return merged.toString();
|
|
152
|
+
};
|
|
153
|
+
exports.mergeURLSearchParams = mergeURLSearchParams;
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { default as isServer } from './is-server';
|
|
2
|
-
export { resolveUrl, isAbsoluteUrl, isTimeoutError } from './utils';
|
|
2
|
+
export { resolveUrl, isAbsoluteUrl, isTimeoutError, isRegexOrUrl, areURLSearchParamsEqual, escapeNonSpecialQuestionMarks, mergeURLSearchParams, getAllowedOriginsFromEnv, } from './utils';
|
|
3
3
|
export { tryParseEnvValue } from './env';
|
|
4
4
|
export { ExperienceEditor, HorizonEditor, isEditorActive, resetEditorChromes, handleEditorAnchors, } from './editing';
|
|
5
5
|
export { DefaultEditFrameButton, DefaultEditFrameButtons, DefaultEditFrameButtonIds, mapButtonToCommand, } from './edit-frame';
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -63,3 +63,77 @@ export const isTimeoutError = (error) => {
|
|
|
63
63
|
((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 408 ||
|
|
64
64
|
error.name === 'AbortError');
|
|
65
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* Gets allowed origins from JSS_ALLOWED_ORIGINS env variable
|
|
68
|
+
* @returns {string[]} list of allowed origins from JSS_ALLOWED_ORIGINS env variable
|
|
69
|
+
*/
|
|
70
|
+
export const getAllowedOriginsFromEnv = () => process.env.JSS_ALLOWED_ORIGINS
|
|
71
|
+
? process.env.JSS_ALLOWED_ORIGINS.replace(' ', '').split(',')
|
|
72
|
+
: [];
|
|
73
|
+
/**
|
|
74
|
+
* Determines whether the given input is a regular expression or resembles a URL.
|
|
75
|
+
* @param {string} input - The input string to evaluate.
|
|
76
|
+
* @returns {'regex' | 'url'} - Returns 'url' if the input looks like a URL, otherwise 'regex'.
|
|
77
|
+
*/
|
|
78
|
+
export const isRegexOrUrl = (input) => {
|
|
79
|
+
// Remove the trailing slash.
|
|
80
|
+
input = input.slice(0, -1);
|
|
81
|
+
// Check if the string resembles a URL.
|
|
82
|
+
const isUrlLike = /^\/[a-zA-Z0-9\-\/]+(\?([a-zA-Z0-9\-_]+=[a-zA-Z0-9\-_]+)(&[a-zA-Z0-9\-_]+=[a-zA-Z0-9\-_]+)*)?$/.test(input);
|
|
83
|
+
if (isUrlLike) {
|
|
84
|
+
return 'url';
|
|
85
|
+
}
|
|
86
|
+
// If it doesn't resemble a URL, it's likely a regular expression.
|
|
87
|
+
return 'regex';
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Compares two URLSearchParams objects to determine if they are equal.
|
|
91
|
+
* @param {URLSearchParams} params1 - The first set of URL search parameters.
|
|
92
|
+
* @param {URLSearchParams} params2 - The second set of URL search parameters.
|
|
93
|
+
* @returns {boolean} - Returns true if the parameters are equal, otherwise false.
|
|
94
|
+
*/
|
|
95
|
+
export const areURLSearchParamsEqual = (params1, params2) => {
|
|
96
|
+
// Generates a sorted string representation of URL search parameters.
|
|
97
|
+
const getSortedParamsString = (params) => {
|
|
98
|
+
return [...params.entries()]
|
|
99
|
+
.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
|
|
100
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
101
|
+
.join('&');
|
|
102
|
+
};
|
|
103
|
+
// Compare the sorted strings of both parameter sets.
|
|
104
|
+
return getSortedParamsString(params1) === getSortedParamsString(params2);
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Escapes non-special "?" characters in a string or regex.
|
|
108
|
+
* - For regular strings, it escapes all unescaped "?" characters by adding a backslash (`\`).
|
|
109
|
+
* - For regex patterns (strings enclosed in `/.../`), it analyzes each "?" to determine if it has special meaning
|
|
110
|
+
* (e.g., `?` in `(abc)?`, `.*?`, `(?!...)`) or is just a literal character. Only literal "?" characters are escaped.
|
|
111
|
+
* @param {string} input - The input string or regex pattern.
|
|
112
|
+
* @returns {string} - The modified string or regex with non-special "?" characters escaped.
|
|
113
|
+
*/
|
|
114
|
+
export const escapeNonSpecialQuestionMarks = (input) => {
|
|
115
|
+
// If the input is already a regex pattern (starts with ^ or ends with $), return it unchanged
|
|
116
|
+
if (input.startsWith('^') || input.endsWith('$')) {
|
|
117
|
+
return input;
|
|
118
|
+
}
|
|
119
|
+
// For non-regex strings, escape literal "?" characters
|
|
120
|
+
return input.replace(/\?/g, '\\?');
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Merges two URLSearchParams objects. If both objects contain the same key, the value from the second object overrides the first.
|
|
124
|
+
* @param {URLSearchParams} params1 - The first set of URL search parameters.
|
|
125
|
+
* @param {URLSearchParams} params2 - The second set of URL search parameters.
|
|
126
|
+
* @returns {string} - A string representation of the merged URL search parameters.
|
|
127
|
+
*/
|
|
128
|
+
export const mergeURLSearchParams = (params1, params2) => {
|
|
129
|
+
const merged = new URLSearchParams();
|
|
130
|
+
// Add all keys and values from the first object.
|
|
131
|
+
for (const [key, value] of params1.entries()) {
|
|
132
|
+
merged.set(key, value);
|
|
133
|
+
}
|
|
134
|
+
// Add all keys and values from the second object, replacing existing ones.
|
|
135
|
+
for (const [key, value] of params2.entries()) {
|
|
136
|
+
merged.set(key, value);
|
|
137
|
+
}
|
|
138
|
+
return merged.toString();
|
|
139
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss",
|
|
3
|
-
"version": "21.10.
|
|
3
|
+
"version": "21.10.1",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
},
|
|
66
66
|
"description": "",
|
|
67
67
|
"types": "types/index.d.ts",
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "aaeb09bfb4b3e9a40f2799342feebfaa4cf5f619",
|
|
69
69
|
"files": [
|
|
70
70
|
"dist",
|
|
71
71
|
"types",
|
package/types/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { default as isServer } from './is-server';
|
|
2
|
-
export { resolveUrl, isAbsoluteUrl, isTimeoutError } from './utils';
|
|
2
|
+
export { resolveUrl, isAbsoluteUrl, isTimeoutError, isRegexOrUrl, areURLSearchParamsEqual, escapeNonSpecialQuestionMarks, mergeURLSearchParams, getAllowedOriginsFromEnv, } from './utils';
|
|
3
3
|
export { tryParseEnvValue } from './env';
|
|
4
4
|
export { ExperienceEditor, HorizonEditor, isEditorActive, resetEditorChromes, handleEditorAnchors, Metadata, } from './editing';
|
|
5
5
|
export { DefaultEditFrameButton, DefaultEditFrameButtons, DefaultEditFrameButtonIds, EditFrameDataSource, ChromeCommand, FieldEditButton, WebEditButton, EditButtonTypes, mapButtonToCommand, } from './edit-frame';
|
package/types/utils/utils.d.ts
CHANGED
|
@@ -16,3 +16,37 @@ export declare const isAbsoluteUrl: (url: string) => boolean;
|
|
|
16
16
|
* @returns {boolean} is timeout error
|
|
17
17
|
*/
|
|
18
18
|
export declare const isTimeoutError: (error: unknown) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Gets allowed origins from JSS_ALLOWED_ORIGINS env variable
|
|
21
|
+
* @returns {string[]} list of allowed origins from JSS_ALLOWED_ORIGINS env variable
|
|
22
|
+
*/
|
|
23
|
+
export declare const getAllowedOriginsFromEnv: () => string[];
|
|
24
|
+
/**
|
|
25
|
+
* Determines whether the given input is a regular expression or resembles a URL.
|
|
26
|
+
* @param {string} input - The input string to evaluate.
|
|
27
|
+
* @returns {'regex' | 'url'} - Returns 'url' if the input looks like a URL, otherwise 'regex'.
|
|
28
|
+
*/
|
|
29
|
+
export declare const isRegexOrUrl: (input: string) => 'regex' | 'url';
|
|
30
|
+
/**
|
|
31
|
+
* Compares two URLSearchParams objects to determine if they are equal.
|
|
32
|
+
* @param {URLSearchParams} params1 - The first set of URL search parameters.
|
|
33
|
+
* @param {URLSearchParams} params2 - The second set of URL search parameters.
|
|
34
|
+
* @returns {boolean} - Returns true if the parameters are equal, otherwise false.
|
|
35
|
+
*/
|
|
36
|
+
export declare const areURLSearchParamsEqual: (params1: URLSearchParams, params2: URLSearchParams) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Escapes non-special "?" characters in a string or regex.
|
|
39
|
+
* - For regular strings, it escapes all unescaped "?" characters by adding a backslash (`\`).
|
|
40
|
+
* - For regex patterns (strings enclosed in `/.../`), it analyzes each "?" to determine if it has special meaning
|
|
41
|
+
* (e.g., `?` in `(abc)?`, `.*?`, `(?!...)`) or is just a literal character. Only literal "?" characters are escaped.
|
|
42
|
+
* @param {string} input - The input string or regex pattern.
|
|
43
|
+
* @returns {string} - The modified string or regex with non-special "?" characters escaped.
|
|
44
|
+
*/
|
|
45
|
+
export declare const escapeNonSpecialQuestionMarks: (input: string) => string;
|
|
46
|
+
/**
|
|
47
|
+
* Merges two URLSearchParams objects. If both objects contain the same key, the value from the second object overrides the first.
|
|
48
|
+
* @param {URLSearchParams} params1 - The first set of URL search parameters.
|
|
49
|
+
* @param {URLSearchParams} params2 - The second set of URL search parameters.
|
|
50
|
+
* @returns {string} - A string representation of the merged URL search parameters.
|
|
51
|
+
*/
|
|
52
|
+
export declare const mergeURLSearchParams: (params1: URLSearchParams, params2: URLSearchParams) => string;
|