@sitecore-content-sdk/core 1.3.0-canary.9 → 1.4.0-canary.2
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/README.md +7 -7
- package/dist/cjs/cache-client.js +55 -54
- package/dist/cjs/client/constants.js +7 -7
- package/dist/cjs/client/edge-proxy.js +24 -22
- package/dist/cjs/client/index.js +15 -15
- package/dist/cjs/client/models.js +2 -2
- package/dist/cjs/client/sitecore-client.js +421 -419
- package/dist/cjs/client/utils.js +47 -46
- package/dist/cjs/config/define-config.js +194 -193
- package/dist/cjs/config/index.js +7 -7
- package/dist/cjs/config/models.js +12 -11
- package/dist/cjs/config-cli/define-cli-config.js +23 -22
- package/dist/cjs/config-cli/index.js +7 -7
- package/dist/cjs/config-cli/models.js +8 -7
- package/dist/cjs/constants.js +49 -17
- package/dist/cjs/debug.js +48 -46
- package/dist/cjs/editing/codegen/index.js +14 -9
- package/dist/cjs/editing/codegen/preview.js +277 -193
- package/dist/cjs/editing/component-layout-service.js +62 -61
- package/dist/cjs/editing/design-library.js +183 -126
- package/dist/cjs/editing/editing-service.js +75 -74
- package/dist/cjs/editing/index.js +33 -27
- package/dist/cjs/editing/metadata.js +42 -42
- package/dist/cjs/editing/models.js +44 -38
- package/dist/cjs/editing/utils.js +108 -90
- package/dist/cjs/form/form.js +81 -78
- package/dist/cjs/form/index.js +7 -7
- package/dist/cjs/graphql-request-client.js +108 -107
- package/dist/cjs/i18n/dictionary-service.js +122 -121
- package/dist/cjs/i18n/index.js +7 -7
- package/dist/cjs/i18n/utils.js +16 -15
- package/dist/cjs/index.js +60 -60
- package/dist/cjs/layout/content-styles.js +72 -71
- package/dist/cjs/layout/index.js +24 -24
- package/dist/cjs/layout/layout-service.js +62 -57
- package/dist/cjs/layout/models.js +39 -34
- package/dist/cjs/layout/themes.js +76 -75
- package/dist/cjs/layout/utils.js +117 -110
- package/dist/cjs/media/index.js +38 -38
- package/dist/cjs/media/media-api.js +100 -96
- package/dist/cjs/models.js +2 -2
- package/dist/cjs/native-fetcher.js +194 -179
- package/dist/cjs/personalize/index.js +15 -15
- package/dist/cjs/personalize/layout-personalizer.js +98 -97
- package/dist/cjs/personalize/personalize-service.js +98 -94
- package/dist/cjs/personalize/utils.js +143 -136
- package/dist/cjs/retries.js +43 -42
- package/dist/cjs/site/error-pages-service.js +65 -64
- package/dist/cjs/site/index.js +26 -26
- package/dist/cjs/site/models.js +2 -2
- package/dist/cjs/site/redirects-service.js +94 -81
- package/dist/cjs/site/robots-service.js +66 -65
- package/dist/cjs/site/site-resolver.js +73 -72
- package/dist/cjs/site/siteinfo-service.js +84 -80
- package/dist/cjs/site/sitemap-xml-service.js +84 -83
- package/dist/cjs/site/sitepath-service.js +165 -164
- package/dist/cjs/site/utils.js +55 -47
- package/dist/cjs/sitecore-service-base.js +36 -36
- package/dist/cjs/tools/auth/flow.js +65 -64
- package/dist/cjs/tools/auth/index.js +5 -5
- package/dist/cjs/tools/auth/models.js +2 -2
- package/dist/cjs/tools/auth/tenant-store.js +38 -38
- package/dist/cjs/tools/codegen/component-generation.js +52 -50
- package/dist/cjs/tools/codegen/extract-files.js +105 -107
- package/dist/cjs/tools/codegen/import-map.js +401 -349
- package/dist/cjs/tools/codegen/utils.js +418 -418
- package/dist/cjs/tools/generate-map.js +2 -2
- package/dist/cjs/tools/generateMetadata.js +36 -35
- package/dist/cjs/tools/generateSites.js +59 -58
- package/dist/cjs/tools/index.js +75 -73
- package/dist/cjs/tools/scaffold.js +60 -59
- package/dist/cjs/tools/templating/components.js +96 -266
- package/dist/cjs/tools/templating/index.js +11 -14
- package/dist/cjs/tools/templating/plugins.js +80 -78
- package/dist/cjs/tools/templating/utils.js +67 -66
- package/dist/cjs/utils/ensurePath.js +20 -20
- package/dist/cjs/utils/env.js +28 -27
- package/dist/cjs/utils/globalCache.js +55 -0
- package/dist/cjs/utils/index.js +26 -21
- package/dist/cjs/utils/is-server.js +11 -10
- package/dist/cjs/utils/normalize-url.js +5 -5
- package/dist/cjs/utils/timeout-promise.js +31 -31
- package/dist/cjs/utils/utils.js +254 -229
- package/dist/esm/cache-client.js +51 -50
- package/dist/esm/client/constants.js +4 -4
- package/dist/esm/client/edge-proxy.js +19 -17
- package/dist/esm/client/index.js +5 -5
- package/dist/esm/client/models.js +1 -1
- package/dist/esm/client/sitecore-client.js +414 -412
- package/dist/esm/client/utils.js +43 -42
- package/dist/esm/config/define-config.js +188 -187
- package/dist/esm/config/index.js +2 -2
- package/dist/esm/config/models.js +9 -8
- package/dist/esm/config-cli/define-cli-config.js +19 -18
- package/dist/esm/config-cli/index.js +2 -2
- package/dist/esm/config-cli/models.js +5 -4
- package/dist/esm/constants.js +46 -14
- package/dist/esm/debug.js +41 -39
- package/dist/esm/editing/codegen/index.js +1 -1
- package/dist/esm/editing/codegen/preview.js +263 -185
- package/dist/esm/editing/component-layout-service.js +55 -54
- package/dist/esm/editing/design-library.js +171 -117
- package/dist/esm/editing/editing-service.js +68 -67
- package/dist/esm/editing/index.js +6 -5
- package/dist/esm/editing/metadata.js +39 -39
- package/dist/esm/editing/models.js +41 -35
- package/dist/esm/editing/utils.js +98 -80
- package/dist/esm/form/form.js +72 -69
- package/dist/esm/form/index.js +1 -1
- package/dist/esm/graphql-request-client.js +101 -100
- package/dist/esm/i18n/dictionary-service.js +115 -114
- package/dist/esm/i18n/index.js +2 -2
- package/dist/esm/i18n/utils.js +13 -12
- package/dist/esm/index.js +13 -13
- package/dist/esm/layout/content-styles.js +64 -63
- package/dist/esm/layout/index.js +6 -6
- package/dist/esm/layout/layout-service.js +55 -50
- package/dist/esm/layout/models.js +36 -31
- package/dist/esm/layout/themes.js +71 -70
- package/dist/esm/layout/utils.js +109 -102
- package/dist/esm/media/index.js +2 -2
- package/dist/esm/media/media-api.js +90 -86
- package/dist/esm/models.js +1 -1
- package/dist/esm/native-fetcher.js +187 -172
- package/dist/esm/personalize/index.js +3 -3
- package/dist/esm/personalize/layout-personalizer.js +93 -92
- package/dist/esm/personalize/personalize-service.js +91 -87
- package/dist/esm/personalize/utils.js +135 -128
- package/dist/esm/retries.js +39 -38
- package/dist/esm/site/error-pages-service.js +58 -57
- package/dist/esm/site/index.js +8 -8
- package/dist/esm/site/models.js +1 -1
- package/dist/esm/site/redirects-service.js +87 -74
- package/dist/esm/site/robots-service.js +59 -58
- package/dist/esm/site/site-resolver.js +69 -68
- package/dist/esm/site/siteinfo-service.js +77 -73
- package/dist/esm/site/sitemap-xml-service.js +77 -76
- package/dist/esm/site/sitepath-service.js +157 -156
- package/dist/esm/site/utils.js +49 -41
- package/dist/esm/sitecore-service-base.js +29 -29
- package/dist/esm/tools/auth/flow.js +62 -61
- package/dist/esm/tools/auth/index.js +1 -1
- package/dist/esm/tools/auth/models.js +1 -1
- package/dist/esm/tools/auth/tenant-store.js +35 -35
- package/dist/esm/tools/codegen/component-generation.js +44 -42
- package/dist/esm/tools/codegen/extract-files.js +99 -101
- package/dist/esm/tools/codegen/import-map.js +358 -306
- package/dist/esm/tools/codegen/utils.js +373 -373
- package/dist/esm/tools/generate-map.js +1 -1
- package/dist/esm/tools/generateMetadata.js +29 -28
- package/dist/esm/tools/generateSites.js +52 -51
- package/dist/esm/tools/index.js +28 -27
- package/dist/esm/tools/scaffold.js +52 -51
- package/dist/esm/tools/templating/components.js +59 -223
- package/dist/esm/tools/templating/index.js +3 -3
- package/dist/esm/tools/templating/plugins.js +72 -70
- package/dist/esm/tools/templating/utils.js +59 -58
- package/dist/esm/utils/ensurePath.js +13 -13
- package/dist/esm/utils/env.js +24 -23
- package/dist/esm/utils/globalCache.js +49 -0
- package/dist/esm/utils/index.js +4 -3
- package/dist/esm/utils/is-server.js +9 -8
- package/dist/esm/utils/normalize-url.js +1 -1
- package/dist/esm/utils/timeout-promise.js +28 -28
- package/dist/esm/utils/utils.js +238 -213
- package/package.json +73 -5
- package/types/cache-client.d.ts +68 -64
- package/types/cache-client.d.ts.map +1 -0
- package/types/client/constants.d.ts +5 -4
- package/types/client/constants.d.ts.map +1 -0
- package/types/client/edge-proxy.d.ts +18 -15
- package/types/client/edge-proxy.d.ts.map +1 -0
- package/types/client/index.d.ts +8 -7
- package/types/client/index.d.ts.map +1 -0
- package/types/client/models.d.ts +21 -19
- package/types/client/models.d.ts.map +1 -0
- package/types/client/sitecore-client.d.ts +338 -327
- package/types/client/sitecore-client.d.ts.map +1 -0
- package/types/client/utils.d.ts +15 -9
- package/types/client/utils.d.ts.map +1 -0
- package/types/config/define-config.d.ts +20 -18
- package/types/config/define-config.d.ts.map +1 -0
- package/types/config/index.d.ts +3 -2
- package/types/config/index.d.ts.map +1 -0
- package/types/config/models.d.ts +287 -268
- package/types/config/models.d.ts.map +1 -0
- package/types/config-cli/define-cli-config.d.ts +9 -7
- package/types/config-cli/define-cli-config.d.ts.map +1 -0
- package/types/config-cli/index.d.ts +3 -2
- package/types/config-cli/index.d.ts.map +1 -0
- package/types/config-cli/models.d.ts +6 -4
- package/types/config-cli/models.d.ts.map +1 -0
- package/types/constants.d.ts +44 -11
- package/types/constants.d.ts.map +1 -0
- package/types/debug.d.ts +35 -28
- package/types/debug.d.ts.map +1 -0
- package/types/editing/codegen/index.d.ts +2 -1
- package/types/editing/codegen/index.d.ts.map +1 -0
- package/types/editing/codegen/preview.d.ts +256 -195
- package/types/editing/codegen/preview.d.ts.map +1 -0
- package/types/editing/component-layout-service.d.ts +84 -80
- package/types/editing/component-layout-service.d.ts.map +1 -0
- package/types/editing/design-library.d.ts +111 -63
- package/types/editing/design-library.d.ts.map +1 -0
- package/types/editing/editing-service.d.ts +72 -62
- package/types/editing/editing-service.d.ts.map +1 -0
- package/types/editing/index.d.ts +7 -6
- package/types/editing/index.d.ts.map +1 -0
- package/types/editing/metadata.d.ts +8 -7
- package/types/editing/metadata.d.ts.map +1 -0
- package/types/editing/models.d.ts +103 -92
- package/types/editing/models.d.ts.map +1 -0
- package/types/editing/utils.d.ts +91 -74
- package/types/editing/utils.d.ts.map +1 -0
- package/types/form/form.d.ts +25 -21
- package/types/form/form.d.ts.map +1 -0
- package/types/form/index.d.ts +2 -1
- package/types/form/index.d.ts.map +1 -0
- package/types/graphql-request-client.d.ts +112 -105
- package/types/graphql-request-client.d.ts.map +1 -0
- package/types/i18n/dictionary-service.d.ts +135 -131
- package/types/i18n/dictionary-service.d.ts.map +1 -0
- package/types/i18n/index.d.ts +3 -2
- package/types/i18n/index.d.ts.map +1 -0
- package/types/i18n/utils.d.ts +9 -7
- package/types/i18n/utils.d.ts.map +1 -0
- package/types/index.d.ts +13 -12
- package/types/index.d.ts.map +1 -0
- package/types/layout/content-styles.d.ts +20 -18
- package/types/layout/content-styles.d.ts.map +1 -0
- package/types/layout/index.d.ts +6 -5
- package/types/layout/index.d.ts.map +1 -0
- package/types/layout/layout-service.d.ts +45 -35
- package/types/layout/layout-service.d.ts.map +1 -0
- package/types/layout/models.d.ts +174 -151
- package/types/layout/models.d.ts.map +1 -0
- package/types/layout/themes.d.ts +13 -11
- package/types/layout/themes.d.ts.map +1 -0
- package/types/layout/utils.d.ts +56 -41
- package/types/layout/utils.d.ts.map +1 -0
- package/types/media/index.d.ts +3 -2
- package/types/media/index.d.ts.map +1 -0
- package/types/media/media-api.d.ts +60 -55
- package/types/media/media-api.d.ts.map +1 -0
- package/types/models.d.ts +94 -84
- package/types/models.d.ts.map +1 -0
- package/types/native-fetcher.d.ts +124 -114
- package/types/native-fetcher.d.ts.map +1 -0
- package/types/personalize/index.d.ts +4 -3
- package/types/personalize/index.d.ts.map +1 -0
- package/types/personalize/layout-personalizer.d.ts +29 -27
- package/types/personalize/layout-personalizer.d.ts.map +1 -0
- package/types/personalize/personalize-service.d.ts +90 -80
- package/types/personalize/personalize-service.d.ts.map +1 -0
- package/types/personalize/utils.d.ts +78 -69
- package/types/personalize/utils.d.ts.map +1 -0
- package/types/retries.d.ts +26 -24
- package/types/retries.d.ts.map +1 -0
- package/types/site/error-pages-service.d.ts +64 -57
- package/types/site/error-pages-service.d.ts.map +1 -0
- package/types/site/index.d.ts +10 -9
- package/types/site/index.d.ts.map +1 -0
- package/types/site/models.d.ts +23 -18
- package/types/site/models.d.ts.map +1 -0
- package/types/site/redirects-service.d.ts +92 -69
- package/types/site/redirects-service.d.ts.map +1 -0
- package/types/site/robots-service.d.ts +57 -50
- package/types/site/robots-service.d.ts.map +1 -0
- package/types/site/site-resolver.d.ts +28 -26
- package/types/site/site-resolver.d.ts.map +1 -0
- package/types/site/siteinfo-service.d.ts +65 -52
- package/types/site/siteinfo-service.d.ts.map +1 -0
- package/types/site/sitemap-xml-service.d.ts +63 -56
- package/types/site/sitemap-xml-service.d.ts.map +1 -0
- package/types/site/sitepath-service.d.ts +137 -134
- package/types/site/sitepath-service.d.ts.map +1 -0
- package/types/site/utils.d.ts +41 -28
- package/types/site/utils.d.ts.map +1 -0
- package/types/sitecore-service-base.d.ts +31 -30
- package/types/sitecore-service-base.d.ts.map +1 -0
- package/types/tools/auth/flow.d.ts +29 -27
- package/types/tools/auth/flow.d.ts.map +1 -0
- package/types/tools/auth/index.d.ts +2 -1
- package/types/tools/auth/index.d.ts.map +1 -0
- package/types/tools/auth/models.d.ts +35 -33
- package/types/tools/auth/models.d.ts.map +1 -0
- package/types/tools/auth/tenant-store.d.ts +12 -11
- package/types/tools/auth/tenant-store.d.ts.map +1 -0
- package/types/tools/codegen/component-generation.d.ts +50 -47
- package/types/tools/codegen/component-generation.d.ts.map +1 -0
- package/types/tools/codegen/extract-files.d.ts +24 -22
- package/types/tools/codegen/extract-files.d.ts.map +1 -0
- package/types/tools/codegen/import-map.d.ts +103 -70
- package/types/tools/codegen/import-map.d.ts.map +1 -0
- package/types/tools/codegen/utils.d.ts +76 -75
- package/types/tools/codegen/utils.d.ts.map +1 -0
- package/types/tools/generate-map.d.ts +36 -26
- package/types/tools/generate-map.d.ts.map +1 -0
- package/types/tools/generateMetadata.d.ts +24 -22
- package/types/tools/generateMetadata.d.ts.map +1 -0
- package/types/tools/generateSites.d.ts +25 -22
- package/types/tools/generateSites.d.ts.map +1 -0
- package/types/tools/index.d.ts +22 -20
- package/types/tools/index.d.ts.map +1 -0
- package/types/tools/scaffold.d.ts +27 -25
- package/types/tools/scaffold.d.ts.map +1 -0
- package/types/tools/templating/components.d.ts +104 -103
- package/types/tools/templating/components.d.ts.map +1 -0
- package/types/tools/templating/index.d.ts +4 -3
- package/types/tools/templating/index.d.ts.map +1 -0
- package/types/tools/templating/plugins.d.ts +71 -67
- package/types/tools/templating/plugins.d.ts.map +1 -0
- package/types/tools/templating/utils.d.ts +42 -40
- package/types/tools/templating/utils.d.ts.map +1 -0
- package/types/utils/ensurePath.d.ts +7 -6
- package/types/utils/ensurePath.d.ts.map +1 -0
- package/types/utils/env.d.ts +9 -7
- package/types/utils/env.d.ts.map +1 -0
- package/types/utils/globalCache.d.ts +37 -0
- package/types/utils/globalCache.d.ts.map +1 -0
- package/types/utils/index.d.ts +5 -3
- package/types/utils/index.d.ts.map +1 -0
- package/types/utils/is-server.d.ts +8 -6
- package/types/utils/is-server.d.ts.map +1 -0
- package/types/utils/normalize-url.d.ts +2 -1
- package/types/utils/normalize-url.d.ts.map +1 -0
- package/types/utils/timeout-promise.d.ts +18 -17
- package/types/utils/timeout-promise.d.ts.map +1 -0
- package/types/utils/utils.d.ts +104 -79
- package/types/utils/utils.d.ts.map +1 -0
- package/client.js +0 -1
- package/codegen.js +0 -1
- package/config-cli.js +0 -1
- package/config.js +0 -1
- package/editing.js +0 -1
- package/i18n.js +0 -1
- package/layout.js +0 -1
- package/media.js +0 -1
- package/personalize.js +0 -1
- package/site.js +0 -1
- package/tools.js +0 -1
- package/utils.js +0 -1
package/dist/cjs/utils/utils.js
CHANGED
|
@@ -1,229 +1,254 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.mergeURLSearchParams = exports.escapeNonSpecialQuestionMarks = exports.areURLSearchParamsEqual = exports.isRegexOrUrl = exports.getEnforcedCorsHeaders = exports.enforceCors = exports.getAllowedOriginsFromEnv = exports.isTimeoutError = exports.isAbsoluteUrl = void 0;
|
|
7
|
-
exports.resolveUrl = resolveUrl;
|
|
8
|
-
const is_server_1 = __importDefault(require("./is-server"));
|
|
9
|
-
/**
|
|
10
|
-
* note: encodeURIComponent is available via browser (window) or natively in node.js
|
|
11
|
-
* if you use another js engine for server-side rendering you may not have native encodeURIComponent
|
|
12
|
-
* and would then need to install a package for that functionality
|
|
13
|
-
* @param {ParsedUrlQueryInput} params query string parameters
|
|
14
|
-
* @returns {string} query string
|
|
15
|
-
*/
|
|
16
|
-
function getQueryString(params) {
|
|
17
|
-
return Object.keys(params)
|
|
18
|
-
.map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(String(params[k]))}`)
|
|
19
|
-
.join('&');
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Resolves a base URL that may contain query string parameters and an additional set of query
|
|
23
|
-
* string parameters into a unified string representation.
|
|
24
|
-
* @param {string} urlBase the base URL that may contain query string parameters
|
|
25
|
-
* @param {ParsedUrlQueryInput} params query string parameters
|
|
26
|
-
* @returns a URL string
|
|
27
|
-
* @throws {RangeError} if the provided url is an empty string
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
*
|
|
81
|
-
* @
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
*
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
*
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.mergeURLSearchParams = exports.escapeNonSpecialQuestionMarks = exports.areURLSearchParamsEqual = exports.isRegexOrUrl = exports.getEnforcedCorsHeaders = exports.enforceCors = exports.getAllowedOriginsFromEnv = exports.isTimeoutError = exports.isAbsoluteUrl = void 0;
|
|
7
|
+
exports.resolveUrl = resolveUrl;
|
|
8
|
+
const is_server_1 = __importDefault(require("./is-server"));
|
|
9
|
+
/**
|
|
10
|
+
* note: encodeURIComponent is available via browser (window) or natively in node.js
|
|
11
|
+
* if you use another js engine for server-side rendering you may not have native encodeURIComponent
|
|
12
|
+
* and would then need to install a package for that functionality
|
|
13
|
+
* @param {ParsedUrlQueryInput} params query string parameters
|
|
14
|
+
* @returns {string} query string
|
|
15
|
+
*/
|
|
16
|
+
function getQueryString(params) {
|
|
17
|
+
return Object.keys(params)
|
|
18
|
+
.map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(String(params[k]))}`)
|
|
19
|
+
.join('&');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolves a base URL that may contain query string parameters and an additional set of query
|
|
23
|
+
* string parameters into a unified string representation.
|
|
24
|
+
* @param {string} urlBase the base URL that may contain query string parameters
|
|
25
|
+
* @param {ParsedUrlQueryInput} params query string parameters
|
|
26
|
+
* @returns a URL string
|
|
27
|
+
* @throws {RangeError} if the provided url is an empty string
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
function resolveUrl(urlBase, params = {}) {
|
|
31
|
+
if (!urlBase) {
|
|
32
|
+
throw new RangeError('url must be a non-empty string');
|
|
33
|
+
}
|
|
34
|
+
// This is a better way to work with URLs since it handles different user input
|
|
35
|
+
// edge cases. This works in Node and all browser except IE11.
|
|
36
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/URL
|
|
37
|
+
// TODO: Verify our browser support requirements.
|
|
38
|
+
if ((0, is_server_1.default)()) {
|
|
39
|
+
const url = new URL(urlBase);
|
|
40
|
+
for (const key in params) {
|
|
41
|
+
if ({}.hasOwnProperty.call(params, key)) {
|
|
42
|
+
url.searchParams.append(key, String(params[key]));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const result = url.toString();
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
const qs = getQueryString(params);
|
|
49
|
+
const result = urlBase.indexOf('?') !== -1 ? `${urlBase}&${qs}` : `${urlBase}?${qs}`;
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Checks if the given URL is an absolute URL
|
|
54
|
+
* @param {string} url - The URL to check.
|
|
55
|
+
* @returns {boolean} - Returns true if the URL is an absolute URL, otherwise false.
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
const isAbsoluteUrl = (url) => {
|
|
59
|
+
if (!url) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (typeof url !== 'string') {
|
|
63
|
+
throw new TypeError('Expected a string');
|
|
64
|
+
}
|
|
65
|
+
return /^[a-z][a-z0-9+.-]*:/.test(url);
|
|
66
|
+
};
|
|
67
|
+
exports.isAbsoluteUrl = isAbsoluteUrl;
|
|
68
|
+
/**
|
|
69
|
+
* Indicates whether the error is a timeout error
|
|
70
|
+
* @param {unknown} error error
|
|
71
|
+
* @returns {boolean} is timeout error
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
const isTimeoutError = (error) => {
|
|
75
|
+
var _a;
|
|
76
|
+
return ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 408 || error.name === 'AbortError';
|
|
77
|
+
};
|
|
78
|
+
exports.isTimeoutError = isTimeoutError;
|
|
79
|
+
/**
|
|
80
|
+
* Converts a string value in a regex pattern allowing wildcard matching
|
|
81
|
+
* @param {string} pattern input with wildcards i.e. site.*.com
|
|
82
|
+
* @returns {string} modified string that can be used as regexp input
|
|
83
|
+
*/
|
|
84
|
+
const convertToWildcardRegex = (pattern) => {
|
|
85
|
+
return '^' + pattern.replace(/\//g, '\\/').replace(/\./g, '\\.').replace(/\*/g, '.*') + '$';
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Gets allowed origins from JSS_ALLOWED_ORIGINS env variable
|
|
89
|
+
* @returns {string[]} list of allowed origins from JSS_ALLOWED_ORIGINS env variable
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
const getAllowedOriginsFromEnv = () => process.env.JSS_ALLOWED_ORIGINS
|
|
93
|
+
? process.env.JSS_ALLOWED_ORIGINS.replace(' ', '').split(',')
|
|
94
|
+
: [];
|
|
95
|
+
exports.getAllowedOriginsFromEnv = getAllowedOriginsFromEnv;
|
|
96
|
+
/**
|
|
97
|
+
* Tests origin from incoming request against allowed origins list that can be
|
|
98
|
+
* set in JSS's JSS_ALLOWED_ORIGINS env variable, passed via allowedOrigins param and/or
|
|
99
|
+
* be already set in Access-Control-Allow-Origin by other logic.
|
|
100
|
+
* Applies Access-Control-Allow-Origin and Access-Control-Allow-Methods on match
|
|
101
|
+
* Also applies Access-Control-Allow-Headers for preflight requests
|
|
102
|
+
* @param {IncomingMessage} req incoming request
|
|
103
|
+
* @param {OutgoingMessage} res response to set CORS headers for
|
|
104
|
+
* @param {string[]} [allowedOrigins] additional list of origins to test against
|
|
105
|
+
* @returns true if incoming origin matches the allowed lists, false when it does not
|
|
106
|
+
* @deprecated use getEnforcedCorsHeaders instead
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
const enforceCors = (req, res, allowedOrigins) => {
|
|
110
|
+
// origin in not present for non-CORS requests (e.g. server-side) - so we skip the checks
|
|
111
|
+
if (!req.headers.origin) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
// 3 sources of allowed origins are considered:
|
|
115
|
+
// the env value
|
|
116
|
+
const defaultAllowedOrigins = (0, exports.getAllowedOriginsFromEnv)();
|
|
117
|
+
// the allowedOrigins prop
|
|
118
|
+
allowedOrigins = defaultAllowedOrigins.concat(allowedOrigins || []);
|
|
119
|
+
// and the existing CORS header, if present (i.e. set by nextjs config)
|
|
120
|
+
const presetCors = res.getHeader('Access-Control-Allow-Origin');
|
|
121
|
+
if (presetCors) {
|
|
122
|
+
allowedOrigins.push(presetCors);
|
|
123
|
+
}
|
|
124
|
+
const origin = req.headers.origin;
|
|
125
|
+
if (origin &&
|
|
126
|
+
allowedOrigins.some((allowedOrigin) => origin === allowedOrigin || new RegExp(convertToWildcardRegex(allowedOrigin)).test(origin))) {
|
|
127
|
+
res.setHeader('Access-Control-Allow-Origin', origin);
|
|
128
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, DELETE, PUT, PATCH');
|
|
129
|
+
// set the allowed headers for preflight requests
|
|
130
|
+
if (req.method === 'OPTIONS') {
|
|
131
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
};
|
|
137
|
+
exports.enforceCors = enforceCors;
|
|
138
|
+
/**
|
|
139
|
+
* Gets enforced CORS headers
|
|
140
|
+
* @param {string} requestMethod - The HTTP method of the request.
|
|
141
|
+
* @param {IncomingHttpHeaders | Headers} headers - The headers of the request.
|
|
142
|
+
* @param {string | string[]} presetCorsHeader - The preset CORS header.
|
|
143
|
+
* @param {string[]} [allowedOrigins] - The allowed origins.
|
|
144
|
+
* @returns {Record<string, string>} - The enforced CORS headers.
|
|
145
|
+
* @public
|
|
146
|
+
*/
|
|
147
|
+
const getEnforcedCorsHeaders = ({ requestMethod, headers, presetCorsHeader, allowedOrigins = [], }) => {
|
|
148
|
+
// ugly but gotta satisfy both node.js and web fetch Headers interface somehow
|
|
149
|
+
const origin = headers.get
|
|
150
|
+
? headers.get('origin')
|
|
151
|
+
: headers.origin;
|
|
152
|
+
if (!origin) {
|
|
153
|
+
return {};
|
|
154
|
+
}
|
|
155
|
+
// 3 sources of allowed origins are considered:
|
|
156
|
+
// the env value
|
|
157
|
+
const defaultAllowedOrigins = (0, exports.getAllowedOriginsFromEnv)();
|
|
158
|
+
// the allowedOrigins prop
|
|
159
|
+
allowedOrigins = defaultAllowedOrigins.concat(allowedOrigins || []);
|
|
160
|
+
// and the existing CORS header, if provided (i.e. from nextjs config)
|
|
161
|
+
if (presetCorsHeader) {
|
|
162
|
+
allowedOrigins.push(presetCorsHeader);
|
|
163
|
+
}
|
|
164
|
+
if (origin &&
|
|
165
|
+
allowedOrigins.some((allowedOrigin) => origin === allowedOrigin || new RegExp(convertToWildcardRegex(allowedOrigin)).test(origin))) {
|
|
166
|
+
const corsHeaders = {
|
|
167
|
+
'Access-Control-Allow-Origin': origin,
|
|
168
|
+
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS, DELETE, PUT, PATCH',
|
|
169
|
+
'x-middleware-cache': 'no-cache',
|
|
170
|
+
'Cache-Control': 'no-store, must-revalidate',
|
|
171
|
+
};
|
|
172
|
+
// set the allowed headers for preflight requests
|
|
173
|
+
if (requestMethod === 'OPTIONS') {
|
|
174
|
+
corsHeaders['Access-Control-Allow-Headers'] = 'Content-Type, Authorization';
|
|
175
|
+
}
|
|
176
|
+
return corsHeaders;
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
};
|
|
180
|
+
exports.getEnforcedCorsHeaders = getEnforcedCorsHeaders;
|
|
181
|
+
/**
|
|
182
|
+
* Determines whether the given input is a regular expression or resembles a URL.
|
|
183
|
+
* @param {string} input - The input string to evaluate.
|
|
184
|
+
* @returns {'regex' | 'url'} - Returns 'url' if the input looks like a URL, otherwise 'regex'.
|
|
185
|
+
* @public
|
|
186
|
+
*/
|
|
187
|
+
const isRegexOrUrl = (input) => {
|
|
188
|
+
// Remove the trailing slash.
|
|
189
|
+
input = input.slice(0, -1);
|
|
190
|
+
// Check if the string resembles a URL.
|
|
191
|
+
const isUrlLike = /^\/[a-zA-Z0-9\-\/]+(\?([a-zA-Z0-9\-_]+=[a-zA-Z0-9\-_]+)(&[a-zA-Z0-9\-_]+=[a-zA-Z0-9\-_]+)*)?$/.test(input);
|
|
192
|
+
if (isUrlLike) {
|
|
193
|
+
return 'url';
|
|
194
|
+
}
|
|
195
|
+
// If it doesn't resemble a URL, it's likely a regular expression.
|
|
196
|
+
return 'regex';
|
|
197
|
+
};
|
|
198
|
+
exports.isRegexOrUrl = isRegexOrUrl;
|
|
199
|
+
/**
|
|
200
|
+
* Compares two URLSearchParams objects to determine if they are equal.
|
|
201
|
+
* @param {URLSearchParams} params1 - The first set of URL search parameters.
|
|
202
|
+
* @param {URLSearchParams} params2 - The second set of URL search parameters.
|
|
203
|
+
* @returns {boolean} - Returns true if the parameters are equal, otherwise false.
|
|
204
|
+
* @public
|
|
205
|
+
*/
|
|
206
|
+
const areURLSearchParamsEqual = (params1, params2) => {
|
|
207
|
+
// Generates a sorted string representation of URL search parameters.
|
|
208
|
+
const getSortedParamsString = (params) => {
|
|
209
|
+
return [...params.entries()]
|
|
210
|
+
.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
|
|
211
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
212
|
+
.join('&');
|
|
213
|
+
};
|
|
214
|
+
// Compare the sorted strings of both parameter sets.
|
|
215
|
+
return getSortedParamsString(params1) === getSortedParamsString(params2);
|
|
216
|
+
};
|
|
217
|
+
exports.areURLSearchParamsEqual = areURLSearchParamsEqual;
|
|
218
|
+
/**
|
|
219
|
+
* Escapes non-special "?" characters in a string or regex.
|
|
220
|
+
* - For regex patterns that start with `^` or end with `$`, it returns the pattern unchanged.
|
|
221
|
+
* - For other strings, it escapes literal "?" characters but preserves regex quantifiers and special patterns.
|
|
222
|
+
* @param {string} input - The input string or regex pattern.
|
|
223
|
+
* @returns {string} - The modified string or regex with non-special "?" characters escaped.
|
|
224
|
+
* @public
|
|
225
|
+
*/
|
|
226
|
+
const escapeNonSpecialQuestionMarks = (input) => {
|
|
227
|
+
// If the input is already a regex pattern (starts with ^ or ends with $), return it unchanged
|
|
228
|
+
if (input.startsWith('^') || input.endsWith('$')) {
|
|
229
|
+
return input;
|
|
230
|
+
}
|
|
231
|
+
// For non-regex strings, escape literal "?" characters
|
|
232
|
+
return input.replace(/\?/g, '\\?');
|
|
233
|
+
};
|
|
234
|
+
exports.escapeNonSpecialQuestionMarks = escapeNonSpecialQuestionMarks;
|
|
235
|
+
/**
|
|
236
|
+
* Merges two URLSearchParams objects. If both objects contain the same key, the value from the second object overrides the first.
|
|
237
|
+
* @param {URLSearchParams} params1 - The first set of URL search parameters.
|
|
238
|
+
* @param {URLSearchParams} params2 - The second set of URL search parameters.
|
|
239
|
+
* @returns {string} - A string representation of the merged URL search parameters.
|
|
240
|
+
* @public
|
|
241
|
+
*/
|
|
242
|
+
const mergeURLSearchParams = (params1, params2) => {
|
|
243
|
+
const merged = new URLSearchParams();
|
|
244
|
+
// Add all keys and values from the first object.
|
|
245
|
+
for (const [key, value] of params1.entries()) {
|
|
246
|
+
merged.set(key, value);
|
|
247
|
+
}
|
|
248
|
+
// Add all keys and values from the second object, replacing existing ones.
|
|
249
|
+
for (const [key, value] of params2.entries()) {
|
|
250
|
+
merged.set(key, value);
|
|
251
|
+
}
|
|
252
|
+
return merged.toString();
|
|
253
|
+
};
|
|
254
|
+
exports.mergeURLSearchParams = mergeURLSearchParams;
|
package/dist/esm/cache-client.js
CHANGED
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
import { Cache } from 'memory-cache';
|
|
2
|
-
/**
|
|
3
|
-
* Default cache configuration
|
|
4
|
-
*/
|
|
5
|
-
const DEFAULTS = Object.freeze({
|
|
6
|
-
cacheTimeout: 60,
|
|
7
|
-
cacheEnabled: true,
|
|
8
|
-
});
|
|
9
|
-
/**
|
|
10
|
-
* A cache client that uses the 'memory-cache' library (https://github.com/ptarjan/node-cache).
|
|
11
|
-
* This class is meant to be extended or used as a mixin; it's not meant to be used directly.
|
|
12
|
-
* @template T The type of data being cached.
|
|
13
|
-
* @mixin
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* @
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
* @
|
|
33
|
-
* @
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
*
|
|
41
|
-
* @
|
|
42
|
-
* @param {
|
|
43
|
-
* @
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
1
|
+
import { Cache } from 'memory-cache';
|
|
2
|
+
/**
|
|
3
|
+
* Default cache configuration
|
|
4
|
+
*/
|
|
5
|
+
const DEFAULTS = Object.freeze({
|
|
6
|
+
cacheTimeout: 60,
|
|
7
|
+
cacheEnabled: true,
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* A cache client that uses the 'memory-cache' library (https://github.com/ptarjan/node-cache).
|
|
11
|
+
* This class is meant to be extended or used as a mixin; it's not meant to be used directly.
|
|
12
|
+
* @template T The type of data being cached.
|
|
13
|
+
* @mixin
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export class MemoryCacheClient {
|
|
17
|
+
/**
|
|
18
|
+
* Initializes a new instance of @see MemoryCacheClient using the provided @see CacheOptions
|
|
19
|
+
* @param {CacheOptions} options Configuration options
|
|
20
|
+
*/
|
|
21
|
+
constructor(options) {
|
|
22
|
+
var _a;
|
|
23
|
+
this.options = options;
|
|
24
|
+
this.cache = new Cache();
|
|
25
|
+
this.options.cacheTimeout = ((_a = this.options.cacheTimeout) !== null && _a !== void 0 ? _a : DEFAULTS.cacheTimeout) * 1000;
|
|
26
|
+
if (this.options.cacheEnabled === undefined) {
|
|
27
|
+
this.options.cacheEnabled = DEFAULTS.cacheEnabled;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves a value from the cache.
|
|
32
|
+
* @template T The type of data being cached.
|
|
33
|
+
* @param {string} key The cache key.
|
|
34
|
+
* @returns The cache value as {T}, or null if the specified key is not found in the cache.
|
|
35
|
+
*/
|
|
36
|
+
getCacheValue(key) {
|
|
37
|
+
return this.options.cacheEnabled ? this.cache.get(key) : null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Adds a value to the cache for the specified cache key.
|
|
41
|
+
* @template T The type of data being cached.
|
|
42
|
+
* @param {string} key The cache key.
|
|
43
|
+
* @param {T} value The value to cache.
|
|
44
|
+
* @returns The value added to the cache.
|
|
45
|
+
*/
|
|
46
|
+
setCacheValue(key, value) {
|
|
47
|
+
return this.options.cacheEnabled
|
|
48
|
+
? this.cache.put(key, value, this.options.cacheTimeout)
|
|
49
|
+
: value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @private */
|
|
2
|
-
export const siteNameError = 'The site name must be a non-empty string';
|
|
3
|
-
/** @private */
|
|
4
|
-
export const languageError = 'The language must be a non-empty string';
|
|
1
|
+
/** @private */
|
|
2
|
+
export const siteNameError = 'The site name must be a non-empty string';
|
|
3
|
+
/** @private */
|
|
4
|
+
export const languageError = 'The language must be a non-empty string';
|