@sitecore-jss/sitecore-jss 0.1.0-beta.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.
Files changed (143) hide show
  1. package/LICENSE.txt +202 -0
  2. package/README.md +7 -0
  3. package/dist/cjs/cache-client.js +54 -0
  4. package/dist/cjs/constants.js +12 -0
  5. package/dist/cjs/debug.js +43 -0
  6. package/dist/cjs/graphql/app-root-query.js +73 -0
  7. package/dist/cjs/graphql/graphql-edge-proxy.js +12 -0
  8. package/dist/cjs/graphql/index.js +11 -0
  9. package/dist/cjs/graphql/search-service.js +60 -0
  10. package/dist/cjs/graphql-request-client.js +106 -0
  11. package/dist/cjs/i18n/dictionary-service.js +45 -0
  12. package/dist/cjs/i18n/graphql-dictionary-service.js +125 -0
  13. package/dist/cjs/i18n/index.js +7 -0
  14. package/dist/cjs/index.js +36 -0
  15. package/dist/cjs/layout/content-styles.js +73 -0
  16. package/dist/cjs/layout/graphql-layout-service.js +84 -0
  17. package/dist/cjs/layout/index.js +18 -0
  18. package/dist/cjs/layout/layout-service.js +9 -0
  19. package/dist/cjs/layout/models.js +27 -0
  20. package/dist/cjs/layout/themes.js +79 -0
  21. package/dist/cjs/layout/utils.js +44 -0
  22. package/dist/cjs/media/index.js +24 -0
  23. package/dist/cjs/media/media-api.js +128 -0
  24. package/dist/cjs/models.js +2 -0
  25. package/dist/cjs/native-fetcher.js +183 -0
  26. package/dist/cjs/personalize/graphql-personalize-service.js +114 -0
  27. package/dist/cjs/personalize/index.js +12 -0
  28. package/dist/cjs/personalize/layout-personalizer.js +75 -0
  29. package/dist/cjs/personalize/utils.js +92 -0
  30. package/dist/cjs/site/graphql-error-pages-service.js +86 -0
  31. package/dist/cjs/site/graphql-redirects-service.js +103 -0
  32. package/dist/cjs/site/graphql-robots-service.js +81 -0
  33. package/dist/cjs/site/graphql-siteinfo-service.js +128 -0
  34. package/dist/cjs/site/graphql-sitemap-service.js +91 -0
  35. package/dist/cjs/site/index.js +22 -0
  36. package/dist/cjs/site/site-resolver.js +79 -0
  37. package/dist/cjs/site/utils.js +43 -0
  38. package/dist/cjs/utils/edit-frame.js +138 -0
  39. package/dist/cjs/utils/editing.js +122 -0
  40. package/dist/cjs/utils/env.js +26 -0
  41. package/dist/cjs/utils/index.js +25 -0
  42. package/dist/cjs/utils/is-server.js +10 -0
  43. package/dist/cjs/utils/timeout-promise.js +31 -0
  44. package/dist/cjs/utils/utils.js +70 -0
  45. package/dist/esm/cache-client.js +50 -0
  46. package/dist/esm/constants.js +9 -0
  47. package/dist/esm/debug.js +36 -0
  48. package/dist/esm/graphql/app-root-query.js +69 -0
  49. package/dist/esm/graphql/graphql-edge-proxy.js +8 -0
  50. package/dist/esm/graphql/index.js +4 -0
  51. package/dist/esm/graphql/search-service.js +56 -0
  52. package/dist/esm/graphql-request-client.js +99 -0
  53. package/dist/esm/i18n/dictionary-service.js +41 -0
  54. package/dist/esm/i18n/graphql-dictionary-service.js +118 -0
  55. package/dist/esm/i18n/index.js +2 -0
  56. package/dist/esm/index.js +7 -0
  57. package/dist/esm/layout/content-styles.js +65 -0
  58. package/dist/esm/layout/graphql-layout-service.js +77 -0
  59. package/dist/esm/layout/index.js +6 -0
  60. package/dist/esm/layout/layout-service.js +5 -0
  61. package/dist/esm/layout/models.js +24 -0
  62. package/dist/esm/layout/themes.js +74 -0
  63. package/dist/esm/layout/utils.js +39 -0
  64. package/dist/esm/media/index.js +2 -0
  65. package/dist/esm/media/media-api.js +117 -0
  66. package/dist/esm/models.js +1 -0
  67. package/dist/esm/native-fetcher.js +176 -0
  68. package/dist/esm/personalize/graphql-personalize-service.js +107 -0
  69. package/dist/esm/personalize/index.js +3 -0
  70. package/dist/esm/personalize/layout-personalizer.js +69 -0
  71. package/dist/esm/personalize/utils.js +85 -0
  72. package/dist/esm/site/graphql-error-pages-service.js +79 -0
  73. package/dist/esm/site/graphql-redirects-service.js +96 -0
  74. package/dist/esm/site/graphql-robots-service.js +74 -0
  75. package/dist/esm/site/graphql-siteinfo-service.js +121 -0
  76. package/dist/esm/site/graphql-sitemap-service.js +84 -0
  77. package/dist/esm/site/index.js +7 -0
  78. package/dist/esm/site/site-resolver.js +75 -0
  79. package/dist/esm/site/utils.js +37 -0
  80. package/dist/esm/utils/edit-frame.js +133 -0
  81. package/dist/esm/utils/editing.js +111 -0
  82. package/dist/esm/utils/env.js +22 -0
  83. package/dist/esm/utils/index.js +5 -0
  84. package/dist/esm/utils/is-server.js +8 -0
  85. package/dist/esm/utils/timeout-promise.js +28 -0
  86. package/dist/esm/utils/utils.js +61 -0
  87. package/graphql.d.ts +1 -0
  88. package/graphql.js +1 -0
  89. package/i18n.d.ts +1 -0
  90. package/i18n.js +1 -0
  91. package/layout.d.ts +1 -0
  92. package/layout.js +1 -0
  93. package/media.d.ts +1 -0
  94. package/media.js +1 -0
  95. package/package.json +71 -0
  96. package/personalize.d.ts +1 -0
  97. package/personalize.js +1 -0
  98. package/site.d.ts +1 -0
  99. package/site.js +1 -0
  100. package/types/cache-client.d.ts +64 -0
  101. package/types/constants.d.ts +6 -0
  102. package/types/debug.d.ts +26 -0
  103. package/types/graphql/app-root-query.d.ts +32 -0
  104. package/types/graphql/graphql-edge-proxy.d.ts +7 -0
  105. package/types/graphql/index.d.ts +4 -0
  106. package/types/graphql/search-service.d.ts +92 -0
  107. package/types/graphql-request-client.d.ts +88 -0
  108. package/types/i18n/dictionary-service.d.ts +56 -0
  109. package/types/i18n/graphql-dictionary-service.d.ts +65 -0
  110. package/types/i18n/index.d.ts +2 -0
  111. package/types/index.d.ts +6 -0
  112. package/types/layout/content-styles.d.ts +18 -0
  113. package/types/layout/graphql-layout-service.d.ts +59 -0
  114. package/types/layout/index.d.ts +6 -0
  115. package/types/layout/layout-service.d.ts +20 -0
  116. package/types/layout/models.d.ts +140 -0
  117. package/types/layout/themes.d.ts +11 -0
  118. package/types/layout/utils.d.ts +17 -0
  119. package/types/media/index.d.ts +2 -0
  120. package/types/media/media-api.d.ts +69 -0
  121. package/types/models.d.ts +6 -0
  122. package/types/native-fetcher.d.ts +92 -0
  123. package/types/personalize/graphql-personalize-service.d.ts +77 -0
  124. package/types/personalize/index.d.ts +3 -0
  125. package/types/personalize/layout-personalizer.d.ts +25 -0
  126. package/types/personalize/utils.d.ts +53 -0
  127. package/types/site/graphql-error-pages-service.d.ts +55 -0
  128. package/types/site/graphql-redirects-service.d.ts +66 -0
  129. package/types/site/graphql-robots-service.d.ts +47 -0
  130. package/types/site/graphql-siteinfo-service.d.ts +69 -0
  131. package/types/site/graphql-sitemap-service.d.ts +53 -0
  132. package/types/site/index.d.ts +7 -0
  133. package/types/site/site-resolver.d.ts +27 -0
  134. package/types/site/utils.d.ts +24 -0
  135. package/types/utils/edit-frame.d.ts +76 -0
  136. package/types/utils/editing.d.ts +58 -0
  137. package/types/utils/env.d.ts +7 -0
  138. package/types/utils/index.d.ts +5 -0
  139. package/types/utils/is-server.d.ts +6 -0
  140. package/types/utils/timeout-promise.d.ts +18 -0
  141. package/types/utils/utils.d.ts +18 -0
  142. package/utils.d.ts +1 -0
  143. package/utils.js +1 -0
package/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # Sitecore JavaScript Rendering SDK
2
+
3
+ This module is provided as a part of Sitecore JavaScript Rendering SDK. It contains the core JSS APIs and utilities.
4
+
5
+ [Documentation](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-javascript-rendering-sdks--jss-.html)
6
+
7
+ [API reference documentation](/ref-docs/sitecore-jss/)
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoryCacheClient = void 0;
4
+ const memory_cache_1 = require("memory-cache");
5
+ /**
6
+ * Default cache configuration
7
+ */
8
+ const DEFAULTS = Object.freeze({
9
+ cacheTimeout: 60,
10
+ cacheEnabled: true,
11
+ });
12
+ /**
13
+ * A cache client that uses the 'memory-cache' library (https://github.com/ptarjan/node-cache).
14
+ * This class is meant to be extended or used as a mixin; it's not meant to be used directly.
15
+ * @template T The type of data being cached.
16
+ * @mixin
17
+ */
18
+ class MemoryCacheClient {
19
+ /**
20
+ * Initializes a new instance of @see MemoryCacheClient using the provided @see CacheOptions
21
+ * @param {CacheOptions} options Configuration options
22
+ */
23
+ constructor(options) {
24
+ var _a;
25
+ this.options = options;
26
+ this.cache = new memory_cache_1.Cache();
27
+ this.options.cacheTimeout = ((_a = this.options.cacheTimeout) !== null && _a !== void 0 ? _a : DEFAULTS.cacheTimeout) * 1000;
28
+ if (this.options.cacheEnabled === undefined) {
29
+ this.options.cacheEnabled = DEFAULTS.cacheEnabled;
30
+ }
31
+ }
32
+ /**
33
+ * Retrieves a value from the cache.
34
+ * @template T The type of data being cached.
35
+ * @param {string} key The cache key.
36
+ * @returns The cache value as {T}, or null if the specified key is not found in the cache.
37
+ */
38
+ getCacheValue(key) {
39
+ return this.options.cacheEnabled ? this.cache.get(key) : null;
40
+ }
41
+ /**
42
+ * Adds a value to the cache for the specified cache key.
43
+ * @template T The type of data being cached.
44
+ * @param {string} key The cache key.
45
+ * @param {T} value The value to cache.
46
+ * @returns The value added to the cache.
47
+ */
48
+ setCacheValue(key, value) {
49
+ return this.options.cacheEnabled
50
+ ? this.cache.put(key, value, this.options.cacheTimeout)
51
+ : value;
52
+ }
53
+ }
54
+ exports.MemoryCacheClient = MemoryCacheClient;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SITECORE_EDGE_URL_DEFAULT = exports.siteNameError = exports.SitecoreTemplateId = void 0;
4
+ var SitecoreTemplateId;
5
+ (function (SitecoreTemplateId) {
6
+ // /sitecore/templates/Foundation/JavaScript Services/App
7
+ SitecoreTemplateId["JssApp"] = "061cba1554744b918a0617903b102b82";
8
+ // /sitecore/templates/System/Dictionary/Dictionary entry
9
+ SitecoreTemplateId["DictionaryEntry"] = "6d1cd89719364a3aa511289a94c2a7b1";
10
+ })(SitecoreTemplateId = exports.SitecoreTemplateId || (exports.SitecoreTemplateId = {}));
11
+ exports.siteNameError = 'The siteName cannot be empty';
12
+ exports.SITECORE_EDGE_URL_DEFAULT = 'https://edge-platform.sitecorecloud.io';
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var _a;
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.enableDebug = void 0;
8
+ const debug_1 = __importDefault(require("debug"));
9
+ const is_server_1 = __importDefault(require("./utils/is-server"));
10
+ const rootNamespace = 'sitecore-jss';
11
+ // On server/node side, allow switching from the built-in
12
+ // `%o` (pretty-print single line) and `%O` (pretty-print multiple line)
13
+ // with a `DEBUG_MULTILINE` environment variable.
14
+ if (is_server_1.default() &&
15
+ ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.DEBUG_MULTILINE) === 'true' &&
16
+ debug_1.default.formatters.o &&
17
+ debug_1.default.formatters.O) {
18
+ debug_1.default.formatters.o = debug_1.default.formatters.O;
19
+ }
20
+ /**
21
+ * Enable debug logging dynamically
22
+ * @param {string} namespaces space-separated list of namespaces to enable
23
+ */
24
+ const enableDebug = (namespaces) => debug_1.default.enable(namespaces);
25
+ exports.enableDebug = enableDebug;
26
+ /**
27
+ * Default Sitecore JSS 'debug' module debuggers. Uses namespace prefix 'sitecore-jss:'.
28
+ * See {@link https://www.npmjs.com/package/debug} for details.
29
+ */
30
+ exports.default = {
31
+ common: debug_1.default(`${rootNamespace}:common`),
32
+ http: debug_1.default(`${rootNamespace}:http`),
33
+ layout: debug_1.default(`${rootNamespace}:layout`),
34
+ dictionary: debug_1.default(`${rootNamespace}:dictionary`),
35
+ editing: debug_1.default(`${rootNamespace}:editing`),
36
+ sitemap: debug_1.default(`${rootNamespace}:sitemap`),
37
+ multisite: debug_1.default(`${rootNamespace}:multisite`),
38
+ robots: debug_1.default(`${rootNamespace}:robots`),
39
+ redirects: debug_1.default(`${rootNamespace}:redirects`),
40
+ personalize: debug_1.default(`${rootNamespace}:personalize`),
41
+ errorpages: debug_1.default(`${rootNamespace}:errorpages`),
42
+ revalidate: debug_1.default(`${rootNamespace}:revalidate`),
43
+ };
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getAppRootId = exports.languageError = exports.siteNameError = void 0;
13
+ const constants_1 = require("../constants");
14
+ /** @private */
15
+ exports.siteNameError = 'The site name must be a non-empty string';
16
+ /** @private */
17
+ exports.languageError = 'The language must be a non-empty string';
18
+ /*
19
+ * GraphQL query that returns the ID of the root item of the specified site and language
20
+ */
21
+ const appRootQuery = /* GraphQL */ `
22
+ query AppRootQuery($jssAppTemplateId: String!, $siteName: String!, $language: String!) {
23
+ layout(site: $siteName, routePath: "/", language: $language) {
24
+ homePage: item {
25
+ rootItem: ancestors(includeTemplateIDs: [$jssAppTemplateId]) {
26
+ id
27
+ }
28
+ }
29
+ }
30
+ }
31
+ `;
32
+ /**
33
+ * Gets the ID of the JSS App root item for the specified site and language.
34
+ * @param {GraphQLClient} client that fetches data from a GraphQL endpoint.
35
+ * @param {string} siteName the name of the Sitecore site.
36
+ * @param {string} language the item language version.
37
+ * @param {string} [jssAppTemplateId] optional template ID of the app root item. If not
38
+ * specified, the ID of the "/sitecore/templates/Foundation/JavaScript Services/App"
39
+ * item is used.
40
+ * @returns the root item ID of the JSS App in Sitecore. Returns null if the app root item is not found.
41
+ * @throws {RangeError} if a valid site name value is not provided.
42
+ * @throws {RangeError} if a valid language value is not provided.
43
+ * @summary This function intentionally avoids throwing an error if a root item is not found,
44
+ * leaving that decision up to implementations.
45
+ */
46
+ function getAppRootId(client, siteName, language, jssAppTemplateId) {
47
+ var _a, _b, _c, _d, _e, _f;
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ if (!siteName) {
50
+ throw new RangeError(exports.siteNameError);
51
+ }
52
+ if (!language) {
53
+ throw new RangeError(exports.languageError);
54
+ }
55
+ let fetchResponse = yield client.request(appRootQuery, {
56
+ jssAppTemplateId: jssAppTemplateId || constants_1.SitecoreTemplateId.JssApp,
57
+ siteName,
58
+ language,
59
+ });
60
+ if (!((_c = (_b = (_a = fetchResponse === null || fetchResponse === void 0 ? void 0 : fetchResponse.layout) === null || _a === void 0 ? void 0 : _a.homePage) === null || _b === void 0 ? void 0 : _b.rootItem) === null || _c === void 0 ? void 0 : _c.length) && language !== 'en') {
61
+ fetchResponse = yield client.request(appRootQuery, {
62
+ jssAppTemplateId: jssAppTemplateId || constants_1.SitecoreTemplateId.JssApp,
63
+ siteName,
64
+ language: 'en',
65
+ });
66
+ }
67
+ if (!((_f = (_e = (_d = fetchResponse === null || fetchResponse === void 0 ? void 0 : fetchResponse.layout) === null || _d === void 0 ? void 0 : _d.homePage) === null || _e === void 0 ? void 0 : _e.rootItem) === null || _f === void 0 ? void 0 : _f.length)) {
68
+ return null;
69
+ }
70
+ return fetchResponse.layout.homePage.rootItem[0].id;
71
+ });
72
+ }
73
+ exports.getAppRootId = getAppRootId;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEdgeProxyContentUrl = void 0;
4
+ const constants_1 = require("../constants");
5
+ /**
6
+ * Generates a URL for accessing Sitecore Edge Platform Content using the provided endpoint and context ID.
7
+ * @param {string} sitecoreEdgeContextId - The unique context id.
8
+ * @param {string} [sitecoreEdgeUrl] - The base endpoint URL for the Edge Platform. Default is https://edge-platform.sitecorecloud.io
9
+ * @returns {string} The complete URL for accessing content through the Edge Platform.
10
+ */
11
+ const getEdgeProxyContentUrl = (sitecoreEdgeContextId, sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) => `${sitecoreEdgeUrl}/v1/content/api/graphql/v1?sitecoreContextId=${sitecoreEdgeContextId}`;
12
+ exports.getEdgeProxyContentUrl = getEdgeProxyContentUrl;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEdgeProxyContentUrl = exports.SearchQueryService = exports.GraphQLRequestClient = exports.getAppRootId = void 0;
4
+ var app_root_query_1 = require("./app-root-query");
5
+ Object.defineProperty(exports, "getAppRootId", { enumerable: true, get: function () { return app_root_query_1.getAppRootId; } });
6
+ var graphql_request_client_1 = require("./../graphql-request-client");
7
+ Object.defineProperty(exports, "GraphQLRequestClient", { enumerable: true, get: function () { return graphql_request_client_1.GraphQLRequestClient; } });
8
+ var search_service_1 = require("./search-service");
9
+ Object.defineProperty(exports, "SearchQueryService", { enumerable: true, get: function () { return search_service_1.SearchQueryService; } });
10
+ var graphql_edge_proxy_1 = require("./graphql-edge-proxy");
11
+ Object.defineProperty(exports, "getEdgeProxyContentUrl", { enumerable: true, get: function () { return graphql_edge_proxy_1.getEdgeProxyContentUrl; } });
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SearchQueryService = void 0;
13
+ /**
14
+ * Provides functionality for performing GraphQL 'search' operations, including handling pagination.
15
+ * This class is meant to be extended or used as a mixin; it's not meant to be used directly.
16
+ * @template T The type of objects being requested.
17
+ * @mixin
18
+ */
19
+ class SearchQueryService {
20
+ /**
21
+ * Creates an instance of search query service.
22
+ * @param {GraphQLClient} client that fetches data from a GraphQL endpoint.
23
+ */
24
+ constructor(client) {
25
+ this.client = client;
26
+ }
27
+ /**
28
+ * 1. Validates mandatory search query arguments
29
+ * 2. Executes search query with pagination
30
+ * 3. Aggregates pagination results into a single result-set.
31
+ * @template T The type of objects being requested.
32
+ * @param {string | DocumentNode} query the search query.
33
+ * @param {SearchQueryVariables} args search query arguments.
34
+ * @returns {T[]} array of result objects.
35
+ * @throws {RangeError} if a valid root item ID is not provided.
36
+ * @throws {RangeError} if the provided language(s) is(are) not valid.
37
+ */
38
+ fetch(query, args) {
39
+ var _a;
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ if (!args.rootItemId) {
42
+ throw new RangeError('"rootItemId" and "language" must be non-empty strings');
43
+ }
44
+ if (!args.language) {
45
+ throw new RangeError('"rootItemId" and "language" must be non-empty strings');
46
+ }
47
+ let results = [];
48
+ let hasNext = true;
49
+ let after = '';
50
+ while (hasNext) {
51
+ const fetchResponse = yield this.client.request(query, Object.assign(Object.assign({}, args), { after }));
52
+ results = results.concat((_a = fetchResponse === null || fetchResponse === void 0 ? void 0 : fetchResponse.search) === null || _a === void 0 ? void 0 : _a.results);
53
+ hasNext = fetchResponse.search.pageInfo.hasNext;
54
+ after = fetchResponse.search.pageInfo.endCursor;
55
+ }
56
+ return results;
57
+ });
58
+ }
59
+ }
60
+ exports.SearchQueryService = SearchQueryService;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.GraphQLRequestClient = void 0;
16
+ const graphql_request_1 = require("graphql-request");
17
+ const url_parse_1 = __importDefault(require("url-parse"));
18
+ const debug_1 = __importDefault(require("./debug"));
19
+ const timeout_promise_1 = __importDefault(require("./utils/timeout-promise"));
20
+ /**
21
+ * A GraphQL client for Sitecore APIs that uses the 'graphql-request' library.
22
+ * https://github.com/prisma-labs/graphql-request
23
+ */
24
+ class GraphQLRequestClient {
25
+ /**
26
+ * Provides ability to execute graphql query using given `endpoint`
27
+ * @param {string} endpoint The Graphql endpoint
28
+ * @param {GraphQLRequestClientConfig} [clientConfig] GraphQL request client configuration.
29
+ */
30
+ constructor(endpoint, clientConfig = {}) {
31
+ this.endpoint = endpoint;
32
+ this.headers = {};
33
+ if (clientConfig.apiKey) {
34
+ this.headers.sc_apikey = clientConfig.apiKey;
35
+ }
36
+ if (!endpoint || !url_parse_1.default(endpoint).hostname) {
37
+ throw new Error(`Invalid GraphQL endpoint '${endpoint}'. Verify that 'layoutServiceHost' property in 'scjssconfig.json' file or appropriate environment variable is set`);
38
+ }
39
+ this.timeout = clientConfig.timeout;
40
+ this.retries = clientConfig.retries || 0;
41
+ this.client = new graphql_request_1.GraphQLClient(endpoint, {
42
+ headers: this.headers,
43
+ fetch: clientConfig.fetch,
44
+ });
45
+ this.debug = clientConfig.debugger || debug_1.default.http;
46
+ }
47
+ /**
48
+ * Factory method for creating a GraphQLRequestClientFactory.
49
+ * @param {Object} config - client configuration options.
50
+ * @param {string} config.endpoint - endpoint
51
+ * @param {string} [config.apiKey] - apikey
52
+ */
53
+ static createClientFactory({ endpoint, apiKey, }) {
54
+ return (config = {}) => new GraphQLRequestClient(endpoint, Object.assign(Object.assign({}, config), { apiKey }));
55
+ }
56
+ /**
57
+ * Execute graphql request
58
+ * @param {string | DocumentNode} query graphql query
59
+ * @param {Object} variables graphql variables
60
+ */
61
+ request(query, variables) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ let retriesLeft = this.retries;
64
+ const retryer = () => __awaiter(this, void 0, void 0, function* () {
65
+ // Note we don't have access to raw request/response with graphql-request
66
+ // but we should log whatever we have.
67
+ this.debug('request: %o', {
68
+ url: this.endpoint,
69
+ headers: this.headers,
70
+ query,
71
+ variables,
72
+ });
73
+ const startTimestamp = Date.now();
74
+ const fetchWithOptionalTimeout = [this.client.request(query, variables)];
75
+ if (this.timeout) {
76
+ this.abortTimeout = new timeout_promise_1.default(this.timeout);
77
+ fetchWithOptionalTimeout.push(this.abortTimeout.start);
78
+ }
79
+ return Promise.race(fetchWithOptionalTimeout).then((data) => {
80
+ var _a;
81
+ (_a = this.abortTimeout) === null || _a === void 0 ? void 0 : _a.clear();
82
+ this.debug('response in %dms: %o', Date.now() - startTimestamp, data);
83
+ return Promise.resolve(data);
84
+ }, (error) => {
85
+ var _a, _b, _c, _d;
86
+ (_a = this.abortTimeout) === null || _a === void 0 ? void 0 : _a.clear();
87
+ this.debug('response error: %o', error.response || error.message || error);
88
+ if (((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) === 429 && retriesLeft > 0) {
89
+ const rawHeaders = (_d = (_c = error) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.headers;
90
+ const delaySeconds = rawHeaders && rawHeaders.get('Retry-After')
91
+ ? Number.parseInt(rawHeaders.get('Retry-After'), 10)
92
+ : 1;
93
+ this.debug('Error: Rate limit reached for GraphQL endpoint. Retrying in %ds. Retries left: %d', delaySeconds, retriesLeft);
94
+ retriesLeft--;
95
+ return new Promise((resolve) => setTimeout(resolve, delaySeconds * 1000)).then(retryer);
96
+ }
97
+ else {
98
+ return Promise.reject(error);
99
+ }
100
+ });
101
+ });
102
+ return retryer();
103
+ });
104
+ }
105
+ }
106
+ exports.GraphQLRequestClient = GraphQLRequestClient;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DictionaryServiceBase = void 0;
4
+ const cache_client_1 = require("../cache-client");
5
+ /**
6
+ * Base implementation of @see DictionaryService that handles caching dictionary values
7
+ */
8
+ class DictionaryServiceBase {
9
+ /**
10
+ * Initializes a new instance of @see DictionaryService using the provided @see CacheOptions
11
+ * @param {CacheOptions} options Configuration options
12
+ */
13
+ constructor(options) {
14
+ this.options = options;
15
+ this.cache = this.getCacheClient();
16
+ }
17
+ /**
18
+ * Caches a @see DictionaryPhrases value for the specified cache key.
19
+ * @param {string} key The cache key.
20
+ * @param {DictionaryPhrases} value The value to cache.
21
+ * @returns The value added to the cache.
22
+ * @mixes CacheClient<DictionaryPhrases>
23
+ */
24
+ setCacheValue(key, value) {
25
+ return this.cache.setCacheValue(key, value);
26
+ }
27
+ /**
28
+ * Retrieves a @see DictionaryPhrases value from the cache.
29
+ * @param {string} key The cache key.
30
+ * @returns The @see DictionaryPhrases value, or null if the specified key is not found in the cache.
31
+ */
32
+ getCacheValue(key) {
33
+ return this.cache.getCacheValue(key);
34
+ }
35
+ /**
36
+ * Gets a cache client that can cache data. Uses memory-cache as the default
37
+ * library for caching (@see MemoryCacheClient). Override this method if you
38
+ * want to use something else.
39
+ * @returns {CacheClient} implementation
40
+ */
41
+ getCacheClient() {
42
+ return new cache_client_1.MemoryCacheClient(this.options);
43
+ }
44
+ }
45
+ exports.DictionaryServiceBase = DictionaryServiceBase;