@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.
Files changed (342) hide show
  1. package/README.md +7 -7
  2. package/dist/cjs/cache-client.js +55 -54
  3. package/dist/cjs/client/constants.js +7 -7
  4. package/dist/cjs/client/edge-proxy.js +24 -22
  5. package/dist/cjs/client/index.js +15 -15
  6. package/dist/cjs/client/models.js +2 -2
  7. package/dist/cjs/client/sitecore-client.js +421 -419
  8. package/dist/cjs/client/utils.js +47 -46
  9. package/dist/cjs/config/define-config.js +194 -193
  10. package/dist/cjs/config/index.js +7 -7
  11. package/dist/cjs/config/models.js +12 -11
  12. package/dist/cjs/config-cli/define-cli-config.js +23 -22
  13. package/dist/cjs/config-cli/index.js +7 -7
  14. package/dist/cjs/config-cli/models.js +8 -7
  15. package/dist/cjs/constants.js +49 -17
  16. package/dist/cjs/debug.js +48 -46
  17. package/dist/cjs/editing/codegen/index.js +14 -9
  18. package/dist/cjs/editing/codegen/preview.js +277 -193
  19. package/dist/cjs/editing/component-layout-service.js +62 -61
  20. package/dist/cjs/editing/design-library.js +183 -126
  21. package/dist/cjs/editing/editing-service.js +75 -74
  22. package/dist/cjs/editing/index.js +33 -27
  23. package/dist/cjs/editing/metadata.js +42 -42
  24. package/dist/cjs/editing/models.js +44 -38
  25. package/dist/cjs/editing/utils.js +108 -90
  26. package/dist/cjs/form/form.js +81 -78
  27. package/dist/cjs/form/index.js +7 -7
  28. package/dist/cjs/graphql-request-client.js +108 -107
  29. package/dist/cjs/i18n/dictionary-service.js +122 -121
  30. package/dist/cjs/i18n/index.js +7 -7
  31. package/dist/cjs/i18n/utils.js +16 -15
  32. package/dist/cjs/index.js +60 -60
  33. package/dist/cjs/layout/content-styles.js +72 -71
  34. package/dist/cjs/layout/index.js +24 -24
  35. package/dist/cjs/layout/layout-service.js +62 -57
  36. package/dist/cjs/layout/models.js +39 -34
  37. package/dist/cjs/layout/themes.js +76 -75
  38. package/dist/cjs/layout/utils.js +117 -110
  39. package/dist/cjs/media/index.js +38 -38
  40. package/dist/cjs/media/media-api.js +100 -96
  41. package/dist/cjs/models.js +2 -2
  42. package/dist/cjs/native-fetcher.js +194 -179
  43. package/dist/cjs/personalize/index.js +15 -15
  44. package/dist/cjs/personalize/layout-personalizer.js +98 -97
  45. package/dist/cjs/personalize/personalize-service.js +98 -94
  46. package/dist/cjs/personalize/utils.js +143 -136
  47. package/dist/cjs/retries.js +43 -42
  48. package/dist/cjs/site/error-pages-service.js +65 -64
  49. package/dist/cjs/site/index.js +26 -26
  50. package/dist/cjs/site/models.js +2 -2
  51. package/dist/cjs/site/redirects-service.js +94 -81
  52. package/dist/cjs/site/robots-service.js +66 -65
  53. package/dist/cjs/site/site-resolver.js +73 -72
  54. package/dist/cjs/site/siteinfo-service.js +84 -80
  55. package/dist/cjs/site/sitemap-xml-service.js +84 -83
  56. package/dist/cjs/site/sitepath-service.js +165 -164
  57. package/dist/cjs/site/utils.js +55 -47
  58. package/dist/cjs/sitecore-service-base.js +36 -36
  59. package/dist/cjs/tools/auth/flow.js +65 -64
  60. package/dist/cjs/tools/auth/index.js +5 -5
  61. package/dist/cjs/tools/auth/models.js +2 -2
  62. package/dist/cjs/tools/auth/tenant-store.js +38 -38
  63. package/dist/cjs/tools/codegen/component-generation.js +52 -50
  64. package/dist/cjs/tools/codegen/extract-files.js +105 -107
  65. package/dist/cjs/tools/codegen/import-map.js +401 -349
  66. package/dist/cjs/tools/codegen/utils.js +418 -418
  67. package/dist/cjs/tools/generate-map.js +2 -2
  68. package/dist/cjs/tools/generateMetadata.js +36 -35
  69. package/dist/cjs/tools/generateSites.js +59 -58
  70. package/dist/cjs/tools/index.js +75 -73
  71. package/dist/cjs/tools/scaffold.js +60 -59
  72. package/dist/cjs/tools/templating/components.js +96 -266
  73. package/dist/cjs/tools/templating/index.js +11 -14
  74. package/dist/cjs/tools/templating/plugins.js +80 -78
  75. package/dist/cjs/tools/templating/utils.js +67 -66
  76. package/dist/cjs/utils/ensurePath.js +20 -20
  77. package/dist/cjs/utils/env.js +28 -27
  78. package/dist/cjs/utils/globalCache.js +55 -0
  79. package/dist/cjs/utils/index.js +26 -21
  80. package/dist/cjs/utils/is-server.js +11 -10
  81. package/dist/cjs/utils/normalize-url.js +5 -5
  82. package/dist/cjs/utils/timeout-promise.js +31 -31
  83. package/dist/cjs/utils/utils.js +254 -229
  84. package/dist/esm/cache-client.js +51 -50
  85. package/dist/esm/client/constants.js +4 -4
  86. package/dist/esm/client/edge-proxy.js +19 -17
  87. package/dist/esm/client/index.js +5 -5
  88. package/dist/esm/client/models.js +1 -1
  89. package/dist/esm/client/sitecore-client.js +414 -412
  90. package/dist/esm/client/utils.js +43 -42
  91. package/dist/esm/config/define-config.js +188 -187
  92. package/dist/esm/config/index.js +2 -2
  93. package/dist/esm/config/models.js +9 -8
  94. package/dist/esm/config-cli/define-cli-config.js +19 -18
  95. package/dist/esm/config-cli/index.js +2 -2
  96. package/dist/esm/config-cli/models.js +5 -4
  97. package/dist/esm/constants.js +46 -14
  98. package/dist/esm/debug.js +41 -39
  99. package/dist/esm/editing/codegen/index.js +1 -1
  100. package/dist/esm/editing/codegen/preview.js +263 -185
  101. package/dist/esm/editing/component-layout-service.js +55 -54
  102. package/dist/esm/editing/design-library.js +171 -117
  103. package/dist/esm/editing/editing-service.js +68 -67
  104. package/dist/esm/editing/index.js +6 -5
  105. package/dist/esm/editing/metadata.js +39 -39
  106. package/dist/esm/editing/models.js +41 -35
  107. package/dist/esm/editing/utils.js +98 -80
  108. package/dist/esm/form/form.js +72 -69
  109. package/dist/esm/form/index.js +1 -1
  110. package/dist/esm/graphql-request-client.js +101 -100
  111. package/dist/esm/i18n/dictionary-service.js +115 -114
  112. package/dist/esm/i18n/index.js +2 -2
  113. package/dist/esm/i18n/utils.js +13 -12
  114. package/dist/esm/index.js +13 -13
  115. package/dist/esm/layout/content-styles.js +64 -63
  116. package/dist/esm/layout/index.js +6 -6
  117. package/dist/esm/layout/layout-service.js +55 -50
  118. package/dist/esm/layout/models.js +36 -31
  119. package/dist/esm/layout/themes.js +71 -70
  120. package/dist/esm/layout/utils.js +109 -102
  121. package/dist/esm/media/index.js +2 -2
  122. package/dist/esm/media/media-api.js +90 -86
  123. package/dist/esm/models.js +1 -1
  124. package/dist/esm/native-fetcher.js +187 -172
  125. package/dist/esm/personalize/index.js +3 -3
  126. package/dist/esm/personalize/layout-personalizer.js +93 -92
  127. package/dist/esm/personalize/personalize-service.js +91 -87
  128. package/dist/esm/personalize/utils.js +135 -128
  129. package/dist/esm/retries.js +39 -38
  130. package/dist/esm/site/error-pages-service.js +58 -57
  131. package/dist/esm/site/index.js +8 -8
  132. package/dist/esm/site/models.js +1 -1
  133. package/dist/esm/site/redirects-service.js +87 -74
  134. package/dist/esm/site/robots-service.js +59 -58
  135. package/dist/esm/site/site-resolver.js +69 -68
  136. package/dist/esm/site/siteinfo-service.js +77 -73
  137. package/dist/esm/site/sitemap-xml-service.js +77 -76
  138. package/dist/esm/site/sitepath-service.js +157 -156
  139. package/dist/esm/site/utils.js +49 -41
  140. package/dist/esm/sitecore-service-base.js +29 -29
  141. package/dist/esm/tools/auth/flow.js +62 -61
  142. package/dist/esm/tools/auth/index.js +1 -1
  143. package/dist/esm/tools/auth/models.js +1 -1
  144. package/dist/esm/tools/auth/tenant-store.js +35 -35
  145. package/dist/esm/tools/codegen/component-generation.js +44 -42
  146. package/dist/esm/tools/codegen/extract-files.js +99 -101
  147. package/dist/esm/tools/codegen/import-map.js +358 -306
  148. package/dist/esm/tools/codegen/utils.js +373 -373
  149. package/dist/esm/tools/generate-map.js +1 -1
  150. package/dist/esm/tools/generateMetadata.js +29 -28
  151. package/dist/esm/tools/generateSites.js +52 -51
  152. package/dist/esm/tools/index.js +28 -27
  153. package/dist/esm/tools/scaffold.js +52 -51
  154. package/dist/esm/tools/templating/components.js +59 -223
  155. package/dist/esm/tools/templating/index.js +3 -3
  156. package/dist/esm/tools/templating/plugins.js +72 -70
  157. package/dist/esm/tools/templating/utils.js +59 -58
  158. package/dist/esm/utils/ensurePath.js +13 -13
  159. package/dist/esm/utils/env.js +24 -23
  160. package/dist/esm/utils/globalCache.js +49 -0
  161. package/dist/esm/utils/index.js +4 -3
  162. package/dist/esm/utils/is-server.js +9 -8
  163. package/dist/esm/utils/normalize-url.js +1 -1
  164. package/dist/esm/utils/timeout-promise.js +28 -28
  165. package/dist/esm/utils/utils.js +238 -213
  166. package/package.json +73 -5
  167. package/types/cache-client.d.ts +68 -64
  168. package/types/cache-client.d.ts.map +1 -0
  169. package/types/client/constants.d.ts +5 -4
  170. package/types/client/constants.d.ts.map +1 -0
  171. package/types/client/edge-proxy.d.ts +18 -15
  172. package/types/client/edge-proxy.d.ts.map +1 -0
  173. package/types/client/index.d.ts +8 -7
  174. package/types/client/index.d.ts.map +1 -0
  175. package/types/client/models.d.ts +21 -19
  176. package/types/client/models.d.ts.map +1 -0
  177. package/types/client/sitecore-client.d.ts +338 -327
  178. package/types/client/sitecore-client.d.ts.map +1 -0
  179. package/types/client/utils.d.ts +15 -9
  180. package/types/client/utils.d.ts.map +1 -0
  181. package/types/config/define-config.d.ts +20 -18
  182. package/types/config/define-config.d.ts.map +1 -0
  183. package/types/config/index.d.ts +3 -2
  184. package/types/config/index.d.ts.map +1 -0
  185. package/types/config/models.d.ts +287 -268
  186. package/types/config/models.d.ts.map +1 -0
  187. package/types/config-cli/define-cli-config.d.ts +9 -7
  188. package/types/config-cli/define-cli-config.d.ts.map +1 -0
  189. package/types/config-cli/index.d.ts +3 -2
  190. package/types/config-cli/index.d.ts.map +1 -0
  191. package/types/config-cli/models.d.ts +6 -4
  192. package/types/config-cli/models.d.ts.map +1 -0
  193. package/types/constants.d.ts +44 -11
  194. package/types/constants.d.ts.map +1 -0
  195. package/types/debug.d.ts +35 -28
  196. package/types/debug.d.ts.map +1 -0
  197. package/types/editing/codegen/index.d.ts +2 -1
  198. package/types/editing/codegen/index.d.ts.map +1 -0
  199. package/types/editing/codegen/preview.d.ts +256 -195
  200. package/types/editing/codegen/preview.d.ts.map +1 -0
  201. package/types/editing/component-layout-service.d.ts +84 -80
  202. package/types/editing/component-layout-service.d.ts.map +1 -0
  203. package/types/editing/design-library.d.ts +111 -63
  204. package/types/editing/design-library.d.ts.map +1 -0
  205. package/types/editing/editing-service.d.ts +72 -62
  206. package/types/editing/editing-service.d.ts.map +1 -0
  207. package/types/editing/index.d.ts +7 -6
  208. package/types/editing/index.d.ts.map +1 -0
  209. package/types/editing/metadata.d.ts +8 -7
  210. package/types/editing/metadata.d.ts.map +1 -0
  211. package/types/editing/models.d.ts +103 -92
  212. package/types/editing/models.d.ts.map +1 -0
  213. package/types/editing/utils.d.ts +91 -74
  214. package/types/editing/utils.d.ts.map +1 -0
  215. package/types/form/form.d.ts +25 -21
  216. package/types/form/form.d.ts.map +1 -0
  217. package/types/form/index.d.ts +2 -1
  218. package/types/form/index.d.ts.map +1 -0
  219. package/types/graphql-request-client.d.ts +112 -105
  220. package/types/graphql-request-client.d.ts.map +1 -0
  221. package/types/i18n/dictionary-service.d.ts +135 -131
  222. package/types/i18n/dictionary-service.d.ts.map +1 -0
  223. package/types/i18n/index.d.ts +3 -2
  224. package/types/i18n/index.d.ts.map +1 -0
  225. package/types/i18n/utils.d.ts +9 -7
  226. package/types/i18n/utils.d.ts.map +1 -0
  227. package/types/index.d.ts +13 -12
  228. package/types/index.d.ts.map +1 -0
  229. package/types/layout/content-styles.d.ts +20 -18
  230. package/types/layout/content-styles.d.ts.map +1 -0
  231. package/types/layout/index.d.ts +6 -5
  232. package/types/layout/index.d.ts.map +1 -0
  233. package/types/layout/layout-service.d.ts +45 -35
  234. package/types/layout/layout-service.d.ts.map +1 -0
  235. package/types/layout/models.d.ts +174 -151
  236. package/types/layout/models.d.ts.map +1 -0
  237. package/types/layout/themes.d.ts +13 -11
  238. package/types/layout/themes.d.ts.map +1 -0
  239. package/types/layout/utils.d.ts +56 -41
  240. package/types/layout/utils.d.ts.map +1 -0
  241. package/types/media/index.d.ts +3 -2
  242. package/types/media/index.d.ts.map +1 -0
  243. package/types/media/media-api.d.ts +60 -55
  244. package/types/media/media-api.d.ts.map +1 -0
  245. package/types/models.d.ts +94 -84
  246. package/types/models.d.ts.map +1 -0
  247. package/types/native-fetcher.d.ts +124 -114
  248. package/types/native-fetcher.d.ts.map +1 -0
  249. package/types/personalize/index.d.ts +4 -3
  250. package/types/personalize/index.d.ts.map +1 -0
  251. package/types/personalize/layout-personalizer.d.ts +29 -27
  252. package/types/personalize/layout-personalizer.d.ts.map +1 -0
  253. package/types/personalize/personalize-service.d.ts +90 -80
  254. package/types/personalize/personalize-service.d.ts.map +1 -0
  255. package/types/personalize/utils.d.ts +78 -69
  256. package/types/personalize/utils.d.ts.map +1 -0
  257. package/types/retries.d.ts +26 -24
  258. package/types/retries.d.ts.map +1 -0
  259. package/types/site/error-pages-service.d.ts +64 -57
  260. package/types/site/error-pages-service.d.ts.map +1 -0
  261. package/types/site/index.d.ts +10 -9
  262. package/types/site/index.d.ts.map +1 -0
  263. package/types/site/models.d.ts +23 -18
  264. package/types/site/models.d.ts.map +1 -0
  265. package/types/site/redirects-service.d.ts +92 -69
  266. package/types/site/redirects-service.d.ts.map +1 -0
  267. package/types/site/robots-service.d.ts +57 -50
  268. package/types/site/robots-service.d.ts.map +1 -0
  269. package/types/site/site-resolver.d.ts +28 -26
  270. package/types/site/site-resolver.d.ts.map +1 -0
  271. package/types/site/siteinfo-service.d.ts +65 -52
  272. package/types/site/siteinfo-service.d.ts.map +1 -0
  273. package/types/site/sitemap-xml-service.d.ts +63 -56
  274. package/types/site/sitemap-xml-service.d.ts.map +1 -0
  275. package/types/site/sitepath-service.d.ts +137 -134
  276. package/types/site/sitepath-service.d.ts.map +1 -0
  277. package/types/site/utils.d.ts +41 -28
  278. package/types/site/utils.d.ts.map +1 -0
  279. package/types/sitecore-service-base.d.ts +31 -30
  280. package/types/sitecore-service-base.d.ts.map +1 -0
  281. package/types/tools/auth/flow.d.ts +29 -27
  282. package/types/tools/auth/flow.d.ts.map +1 -0
  283. package/types/tools/auth/index.d.ts +2 -1
  284. package/types/tools/auth/index.d.ts.map +1 -0
  285. package/types/tools/auth/models.d.ts +35 -33
  286. package/types/tools/auth/models.d.ts.map +1 -0
  287. package/types/tools/auth/tenant-store.d.ts +12 -11
  288. package/types/tools/auth/tenant-store.d.ts.map +1 -0
  289. package/types/tools/codegen/component-generation.d.ts +50 -47
  290. package/types/tools/codegen/component-generation.d.ts.map +1 -0
  291. package/types/tools/codegen/extract-files.d.ts +24 -22
  292. package/types/tools/codegen/extract-files.d.ts.map +1 -0
  293. package/types/tools/codegen/import-map.d.ts +103 -70
  294. package/types/tools/codegen/import-map.d.ts.map +1 -0
  295. package/types/tools/codegen/utils.d.ts +76 -75
  296. package/types/tools/codegen/utils.d.ts.map +1 -0
  297. package/types/tools/generate-map.d.ts +36 -26
  298. package/types/tools/generate-map.d.ts.map +1 -0
  299. package/types/tools/generateMetadata.d.ts +24 -22
  300. package/types/tools/generateMetadata.d.ts.map +1 -0
  301. package/types/tools/generateSites.d.ts +25 -22
  302. package/types/tools/generateSites.d.ts.map +1 -0
  303. package/types/tools/index.d.ts +22 -20
  304. package/types/tools/index.d.ts.map +1 -0
  305. package/types/tools/scaffold.d.ts +27 -25
  306. package/types/tools/scaffold.d.ts.map +1 -0
  307. package/types/tools/templating/components.d.ts +104 -103
  308. package/types/tools/templating/components.d.ts.map +1 -0
  309. package/types/tools/templating/index.d.ts +4 -3
  310. package/types/tools/templating/index.d.ts.map +1 -0
  311. package/types/tools/templating/plugins.d.ts +71 -67
  312. package/types/tools/templating/plugins.d.ts.map +1 -0
  313. package/types/tools/templating/utils.d.ts +42 -40
  314. package/types/tools/templating/utils.d.ts.map +1 -0
  315. package/types/utils/ensurePath.d.ts +7 -6
  316. package/types/utils/ensurePath.d.ts.map +1 -0
  317. package/types/utils/env.d.ts +9 -7
  318. package/types/utils/env.d.ts.map +1 -0
  319. package/types/utils/globalCache.d.ts +37 -0
  320. package/types/utils/globalCache.d.ts.map +1 -0
  321. package/types/utils/index.d.ts +5 -3
  322. package/types/utils/index.d.ts.map +1 -0
  323. package/types/utils/is-server.d.ts +8 -6
  324. package/types/utils/is-server.d.ts.map +1 -0
  325. package/types/utils/normalize-url.d.ts +2 -1
  326. package/types/utils/normalize-url.d.ts.map +1 -0
  327. package/types/utils/timeout-promise.d.ts +18 -17
  328. package/types/utils/timeout-promise.d.ts.map +1 -0
  329. package/types/utils/utils.d.ts +104 -79
  330. package/types/utils/utils.d.ts.map +1 -0
  331. package/client.js +0 -1
  332. package/codegen.js +0 -1
  333. package/config-cli.js +0 -1
  334. package/config.js +0 -1
  335. package/editing.js +0 -1
  336. package/i18n.js +0 -1
  337. package/layout.js +0 -1
  338. package/media.js +0 -1
  339. package/personalize.js +0 -1
  340. package/site.js +0 -1
  341. package/tools.js +0 -1
  342. package/utils.js +0 -1
@@ -1,107 +1,108 @@
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.GraphQLRequestClient = void 0;
7
- const graphql_request_1 = require("graphql-request");
8
- const url_parse_1 = __importDefault(require("url-parse"));
9
- const debug_1 = __importDefault(require("./debug"));
10
- const timeout_promise_1 = __importDefault(require("./utils/timeout-promise"));
11
- const retries_1 = require("./retries");
12
- /**
13
- * A GraphQL client for Sitecore APIs that uses the 'graphql-request' library.
14
- * https://github.com/prisma-labs/graphql-request
15
- */
16
- class GraphQLRequestClient {
17
- /**
18
- * Provides ability to execute graphql query using given `endpoint`
19
- * @param {string} endpoint The Graphql endpoint
20
- * @param {GraphQLRequestClientConfig} [clientConfig] GraphQL request client configuration.
21
- */
22
- constructor(endpoint, clientConfig = {}) {
23
- var _a;
24
- this.endpoint = endpoint;
25
- this.headers = {};
26
- if (clientConfig.apiKey) {
27
- this.headers.sc_apikey = clientConfig.apiKey;
28
- }
29
- if (clientConfig.headers) {
30
- this.headers = Object.assign(Object.assign({}, this.headers), clientConfig.headers);
31
- }
32
- if (!endpoint || !(0, url_parse_1.default)(endpoint).hostname) {
33
- throw new Error(`Invalid GraphQL endpoint '${endpoint}'. Verify that appropriate environment variable is set`);
34
- }
35
- this.timeout = clientConfig.timeout;
36
- this.retries = (_a = clientConfig.retries) !== null && _a !== void 0 ? _a : 3;
37
- this.retryStrategy =
38
- clientConfig.retryStrategy ||
39
- new retries_1.DefaultRetryStrategy({ statusCodes: [429, 502, 503, 504, 520, 521, 522, 523, 524] });
40
- this.client = new graphql_request_1.GraphQLClient(endpoint, {
41
- headers: this.headers,
42
- fetch: clientConfig.fetch,
43
- });
44
- this.debug = clientConfig.debugger || debug_1.default.http;
45
- }
46
- /**
47
- * Factory method for creating a GraphQLRequestClientFactory.
48
- * @param {object} config - client configuration options.
49
- * @param {string} config.endpoint - endpoint
50
- * @param {string} [config.apiKey] - apikey
51
- */
52
- static createClientFactory({ endpoint, apiKey, }) {
53
- return (config = {}) => new GraphQLRequestClient(endpoint, Object.assign(Object.assign({}, config), { apiKey }));
54
- }
55
- /**
56
- * Execute graphql request
57
- * @param {string | DocumentNode} query graphql query
58
- * @param {RequestOptions} [options] Options for configuring a GraphQL request.
59
- */
60
- async request(query, variables, options) {
61
- let attempt = 1;
62
- const retryer = async () => {
63
- const retries = (options === null || options === void 0 ? void 0 : options.retries) || this.retries;
64
- const retryStrategy = (options === null || options === void 0 ? void 0 : options.retryStrategy) || this.retryStrategy;
65
- const debug = (options === null || options === void 0 ? void 0 : options.debugger) || this.debug;
66
- // Note we don't have access to raw request/response with graphql-request
67
- // but we should log whatever we have.
68
- debug('request: %o', {
69
- url: this.endpoint,
70
- headers: Object.assign(Object.assign({}, this.headers), options === null || options === void 0 ? void 0 : options.headers),
71
- query,
72
- variables,
73
- timeout: this.timeout,
74
- });
75
- const startTimestamp = Date.now();
76
- const headers = Object.assign(Object.assign({}, this.headers), options === null || options === void 0 ? void 0 : options.headers);
77
- const fetchWithOptionalTimeout = [this.client.request(query, variables, headers)];
78
- if (this.timeout) {
79
- this.abortTimeout = new timeout_promise_1.default(this.timeout);
80
- fetchWithOptionalTimeout.push(this.abortTimeout.start);
81
- }
82
- return Promise.race(fetchWithOptionalTimeout).then((data) => {
83
- var _a;
84
- (_a = this.abortTimeout) === null || _a === void 0 ? void 0 : _a.clear();
85
- this.debug('response in %dms: %o', Date.now() - startTimestamp, data);
86
- return Promise.resolve(data);
87
- }, async (error) => {
88
- var _a, _b;
89
- (_a = this.abortTimeout) === null || _a === void 0 ? void 0 : _a.clear();
90
- debug('response error: %o', error.response || error.message || error);
91
- const status = ((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) || error.code;
92
- const shouldRetry = retryStrategy.shouldRetry(error, attempt, retries);
93
- if (shouldRetry) {
94
- const delayMs = retryStrategy.getDelay(error, attempt);
95
- debug('Error: %s. Retrying in %dms (attempt %d).', status, delayMs, attempt);
96
- attempt++;
97
- return new Promise((resolve) => setTimeout(resolve, delayMs)).then(retryer);
98
- }
99
- else {
100
- return Promise.reject(error);
101
- }
102
- });
103
- };
104
- return retryer();
105
- }
106
- }
107
- exports.GraphQLRequestClient = GraphQLRequestClient;
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.GraphQLRequestClient = void 0;
7
+ const graphql_request_1 = require("graphql-request");
8
+ const url_parse_1 = __importDefault(require("url-parse"));
9
+ const debug_1 = __importDefault(require("./debug"));
10
+ const timeout_promise_1 = __importDefault(require("./utils/timeout-promise"));
11
+ const retries_1 = require("./retries");
12
+ /**
13
+ * A GraphQL client for Sitecore APIs that uses the 'graphql-request' library.
14
+ * https://github.com/prisma-labs/graphql-request
15
+ * @public
16
+ */
17
+ class GraphQLRequestClient {
18
+ /**
19
+ * Provides ability to execute graphql query using given `endpoint`
20
+ * @param {string} endpoint The Graphql endpoint
21
+ * @param {GraphQLRequestClientConfig} [clientConfig] GraphQL request client configuration.
22
+ */
23
+ constructor(endpoint, clientConfig = {}) {
24
+ var _a;
25
+ this.endpoint = endpoint;
26
+ this.headers = {};
27
+ if (clientConfig.apiKey) {
28
+ this.headers.sc_apikey = clientConfig.apiKey;
29
+ }
30
+ if (clientConfig.headers) {
31
+ this.headers = Object.assign(Object.assign({}, this.headers), clientConfig.headers);
32
+ }
33
+ if (!endpoint || !(0, url_parse_1.default)(endpoint).hostname) {
34
+ throw new Error(`Invalid GraphQL endpoint '${endpoint}'. Verify that appropriate environment variable is set`);
35
+ }
36
+ this.timeout = clientConfig.timeout;
37
+ this.retries = (_a = clientConfig.retries) !== null && _a !== void 0 ? _a : 3;
38
+ this.retryStrategy =
39
+ clientConfig.retryStrategy ||
40
+ new retries_1.DefaultRetryStrategy({ statusCodes: [429, 502, 503, 504, 520, 521, 522, 523, 524] });
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 {RequestOptions} [options] Options for configuring a GraphQL request.
60
+ */
61
+ async request(query, variables, options) {
62
+ let attempt = 1;
63
+ const retryer = async () => {
64
+ const retries = (options === null || options === void 0 ? void 0 : options.retries) || this.retries;
65
+ const retryStrategy = (options === null || options === void 0 ? void 0 : options.retryStrategy) || this.retryStrategy;
66
+ const debug = (options === null || options === void 0 ? void 0 : options.debugger) || this.debug;
67
+ // Note we don't have access to raw request/response with graphql-request
68
+ // but we should log whatever we have.
69
+ debug('request: %o', {
70
+ url: this.endpoint,
71
+ headers: Object.assign(Object.assign({}, this.headers), options === null || options === void 0 ? void 0 : options.headers),
72
+ query,
73
+ variables,
74
+ timeout: this.timeout,
75
+ });
76
+ const startTimestamp = Date.now();
77
+ const headers = Object.assign(Object.assign({}, this.headers), options === null || options === void 0 ? void 0 : options.headers);
78
+ const fetchWithOptionalTimeout = [this.client.request(query, variables, headers)];
79
+ if (this.timeout) {
80
+ this.abortTimeout = new timeout_promise_1.default(this.timeout);
81
+ fetchWithOptionalTimeout.push(this.abortTimeout.start);
82
+ }
83
+ return Promise.race(fetchWithOptionalTimeout).then((data) => {
84
+ var _a;
85
+ (_a = this.abortTimeout) === null || _a === void 0 ? void 0 : _a.clear();
86
+ this.debug('response in %dms: %o', Date.now() - startTimestamp, data);
87
+ return Promise.resolve(data);
88
+ }, async (error) => {
89
+ var _a, _b;
90
+ (_a = this.abortTimeout) === null || _a === void 0 ? void 0 : _a.clear();
91
+ debug('response error: %o', error.response || error.message || error);
92
+ const status = ((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) || error.code;
93
+ const shouldRetry = retryStrategy.shouldRetry(error, attempt, retries);
94
+ if (shouldRetry) {
95
+ const delayMs = retryStrategy.getDelay(error, attempt);
96
+ debug('Error: %s. Retrying in %dms (attempt %d).', status, delayMs, attempt);
97
+ attempt++;
98
+ return new Promise((resolve) => setTimeout(resolve, delayMs)).then(retryer);
99
+ }
100
+ else {
101
+ return Promise.reject(error);
102
+ }
103
+ });
104
+ };
105
+ return retryer();
106
+ }
107
+ }
108
+ exports.GraphQLRequestClient = GraphQLRequestClient;
@@ -1,15 +1,15 @@
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.DictionaryService = exports.queryError = void 0;
7
- const cache_client_1 = require("../cache-client");
8
- const constants_1 = require("../client/constants");
9
- const debug_1 = __importDefault(require("../debug"));
10
- /** @private */
11
- exports.queryError = 'Valid value for rootItemId not provided and failed to auto-resolve app root item.';
12
- /** @default */
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.DictionaryService = exports.queryError = void 0;
7
+ const cache_client_1 = require("../cache-client");
8
+ const constants_1 = require("../client/constants");
9
+ const debug_1 = __importDefault(require("../debug"));
10
+ /** @private */
11
+ exports.queryError = 'Valid value for rootItemId not provided and failed to auto-resolve app root item.';
12
+ /** @default */
13
13
  const siteQuery = /* GraphQL */ `
14
14
  query DictionarySiteQuery(
15
15
  $siteName: String!
@@ -32,112 +32,113 @@ const siteQuery = /* GraphQL */ `
32
32
  }
33
33
  }
34
34
  }
35
- `;
36
- /**
37
- * Service that fetch dictionary data using Sitecore's GraphQL API.
38
- * @augments DictionaryServiceBase
39
- * @mixes SearchQueryService<DictionaryQueryResult>
40
- */
41
- class DictionaryService {
42
- /**
43
- * Creates an instance of graphQL dictionary service with the provided options
44
- * @param {DictionaryService} options instance
45
- */
46
- constructor(options) {
47
- this.options = options;
48
- this.cache = this.getCacheClient();
49
- this.graphQLClient = this.getGraphQLClient();
50
- }
51
- /**
52
- * Fetches dictionary data for internalization. Uses search query by default
53
- * @param {string} language the language to fetch
54
- * @param {string} site site name to fetch data for.
55
- * @param {FetchOptions} [fetchOptions] Options to override graphQL client details like retries and fetch implementation
56
- * @returns {Promise<DictionaryPhrases>} dictionary phrases
57
- * @throws {Error} if the app root was not found for the specified site and language.
58
- */
59
- async fetchDictionaryData(language, site, fetchOptions) {
60
- var _a, _b;
61
- const cacheKey = site + language;
62
- const cachedValue = this.getCacheValue(cacheKey);
63
- if (cachedValue) {
64
- debug_1.default.dictionary('using cached dictionary data for %s %s', language, site);
65
- return cachedValue;
66
- }
67
- const phrases = {};
68
- debug_1.default.dictionary('fetching dictionary data for %s %s', language, site);
69
- let results = [];
70
- let hasNext = true;
71
- let after = '';
72
- if (!site) {
73
- throw new RangeError(constants_1.siteNameError);
74
- }
75
- if (!language) {
76
- throw new RangeError(constants_1.languageError);
77
- }
78
- while (hasNext) {
79
- const fetchResponse = await this.graphQLClient.request(siteQuery, {
80
- siteName: site,
81
- language,
82
- pageSize: this.options.pageSize,
83
- after,
84
- }, fetchOptions);
85
- if ((_b = (_a = fetchResponse === null || fetchResponse === void 0 ? void 0 : fetchResponse.site) === null || _a === void 0 ? void 0 : _a.siteInfo) === null || _b === void 0 ? void 0 : _b.dictionary) {
86
- results = results.concat(fetchResponse.site.siteInfo.dictionary.results);
87
- after = fetchResponse.site.siteInfo.dictionary.pageInfo.endCursor;
88
- hasNext = fetchResponse.site.siteInfo.dictionary.pageInfo.hasNext;
89
- }
90
- else {
91
- hasNext = false;
92
- }
93
- }
94
- results.forEach((item) => (phrases[item.key] = item.value));
95
- this.setCacheValue(cacheKey, phrases);
96
- return phrases;
97
- }
98
- /**
99
- * Caches a @see DictionaryPhrases value for the specified cache key.
100
- * @param {string} key The cache key.
101
- * @param {DictionaryPhrases} value The value to cache.
102
- * @returns The value added to the cache.
103
- * @mixes CacheClient<DictionaryPhrases>
104
- */
105
- setCacheValue(key, value) {
106
- return this.cache.setCacheValue(key, value);
107
- }
108
- /**
109
- * Retrieves a @see DictionaryPhrases value from the cache.
110
- * @param {string} key The cache key.
111
- * @returns The @see DictionaryPhrases value, or null if the specified key is not found in the cache.
112
- */
113
- getCacheValue(key) {
114
- return this.cache.getCacheValue(key);
115
- }
116
- /**
117
- * Gets a cache client that can cache data. Uses memory-cache as the default
118
- * library for caching (@see MemoryCacheClient). Override this method if you
119
- * want to use something else.
120
- * @returns {CacheClient} implementation
121
- */
122
- getCacheClient() {
123
- return new cache_client_1.MemoryCacheClient(this.options);
124
- }
125
- /**
126
- * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
127
- * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
128
- * want to use something else.
129
- * @returns {GraphQLClient} implementation
130
- */
131
- getGraphQLClient() {
132
- var _a, _b;
133
- if (!this.options.clientFactory) {
134
- throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
135
- }
136
- return this.options.clientFactory({
137
- debugger: debug_1.default.dictionary,
138
- retries: (_a = this.options.retries) === null || _a === void 0 ? void 0 : _a.count,
139
- retryStrategy: (_b = this.options.retries) === null || _b === void 0 ? void 0 : _b.retryStrategy,
140
- });
141
- }
142
- }
143
- exports.DictionaryService = DictionaryService;
35
+ `;
36
+ /**
37
+ * Service that fetch dictionary data using Sitecore's GraphQL API.
38
+ * @augments DictionaryServiceBase
39
+ * @mixes SearchQueryService<DictionaryQueryResult>
40
+ * @public
41
+ */
42
+ class DictionaryService {
43
+ /**
44
+ * Creates an instance of graphQL dictionary service with the provided options
45
+ * @param {DictionaryService} options instance
46
+ */
47
+ constructor(options) {
48
+ this.options = options;
49
+ this.cache = this.getCacheClient();
50
+ this.graphQLClient = this.getGraphQLClient();
51
+ }
52
+ /**
53
+ * Fetches dictionary data for internalization. Uses search query by default
54
+ * @param {string} language the language to fetch
55
+ * @param {string} site site name to fetch data for.
56
+ * @param {FetchOptions} [fetchOptions] Options to override graphQL client details like retries and fetch implementation
57
+ * @returns {Promise<DictionaryPhrases>} dictionary phrases
58
+ * @throws {Error} if the app root was not found for the specified site and language.
59
+ */
60
+ async fetchDictionaryData(language, site, fetchOptions) {
61
+ var _a, _b;
62
+ const cacheKey = site + language;
63
+ const cachedValue = this.getCacheValue(cacheKey);
64
+ if (cachedValue) {
65
+ debug_1.default.dictionary('using cached dictionary data for %s %s', language, site);
66
+ return cachedValue;
67
+ }
68
+ const phrases = {};
69
+ debug_1.default.dictionary('fetching dictionary data for %s %s', language, site);
70
+ let results = [];
71
+ let hasNext = true;
72
+ let after = '';
73
+ if (!site) {
74
+ throw new RangeError(constants_1.siteNameError);
75
+ }
76
+ if (!language) {
77
+ throw new RangeError(constants_1.languageError);
78
+ }
79
+ while (hasNext) {
80
+ const fetchResponse = await this.graphQLClient.request(siteQuery, {
81
+ siteName: site,
82
+ language,
83
+ pageSize: this.options.pageSize,
84
+ after,
85
+ }, fetchOptions);
86
+ if ((_b = (_a = fetchResponse === null || fetchResponse === void 0 ? void 0 : fetchResponse.site) === null || _a === void 0 ? void 0 : _a.siteInfo) === null || _b === void 0 ? void 0 : _b.dictionary) {
87
+ results = results.concat(fetchResponse.site.siteInfo.dictionary.results);
88
+ after = fetchResponse.site.siteInfo.dictionary.pageInfo.endCursor;
89
+ hasNext = fetchResponse.site.siteInfo.dictionary.pageInfo.hasNext;
90
+ }
91
+ else {
92
+ hasNext = false;
93
+ }
94
+ }
95
+ results.forEach((item) => (phrases[item.key] = item.value));
96
+ this.setCacheValue(cacheKey, phrases);
97
+ return phrases;
98
+ }
99
+ /**
100
+ * Caches a @see DictionaryPhrases value for the specified cache key.
101
+ * @param {string} key The cache key.
102
+ * @param {DictionaryPhrases} value The value to cache.
103
+ * @returns The value added to the cache.
104
+ * @mixes CacheClient<DictionaryPhrases>
105
+ */
106
+ setCacheValue(key, value) {
107
+ return this.cache.setCacheValue(key, value);
108
+ }
109
+ /**
110
+ * Retrieves a @see DictionaryPhrases value from the cache.
111
+ * @param {string} key The cache key.
112
+ * @returns The @see DictionaryPhrases value, or null if the specified key is not found in the cache.
113
+ */
114
+ getCacheValue(key) {
115
+ return this.cache.getCacheValue(key);
116
+ }
117
+ /**
118
+ * Gets a cache client that can cache data. Uses memory-cache as the default
119
+ * library for caching (@see MemoryCacheClient). Override this method if you
120
+ * want to use something else.
121
+ * @returns {CacheClient} implementation
122
+ */
123
+ getCacheClient() {
124
+ return new cache_client_1.MemoryCacheClient(this.options);
125
+ }
126
+ /**
127
+ * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
128
+ * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
129
+ * want to use something else.
130
+ * @returns {GraphQLClient} implementation
131
+ */
132
+ getGraphQLClient() {
133
+ var _a, _b;
134
+ if (!this.options.clientFactory) {
135
+ throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
136
+ }
137
+ return this.options.clientFactory({
138
+ debugger: debug_1.default.dictionary,
139
+ retries: (_a = this.options.retries) === null || _a === void 0 ? void 0 : _a.count,
140
+ retryStrategy: (_b = this.options.retries) === null || _b === void 0 ? void 0 : _b.retryStrategy,
141
+ });
142
+ }
143
+ }
144
+ exports.DictionaryService = DictionaryService;
@@ -1,7 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLocaleRewrite = exports.DictionaryService = void 0;
4
- var dictionary_service_1 = require("./dictionary-service");
5
- Object.defineProperty(exports, "DictionaryService", { enumerable: true, get: function () { return dictionary_service_1.DictionaryService; } });
6
- var utils_1 = require("./utils");
7
- Object.defineProperty(exports, "getLocaleRewrite", { enumerable: true, get: function () { return utils_1.getLocaleRewrite; } });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLocaleRewrite = exports.DictionaryService = void 0;
4
+ var dictionary_service_1 = require("./dictionary-service");
5
+ Object.defineProperty(exports, "DictionaryService", { enumerable: true, get: function () { return dictionary_service_1.DictionaryService; } });
6
+ var utils_1 = require("./utils");
7
+ Object.defineProperty(exports, "getLocaleRewrite", { enumerable: true, get: function () { return utils_1.getLocaleRewrite; } });
@@ -1,15 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLocaleRewrite = getLocaleRewrite;
4
- /**
5
- * Get a locale rewrite path for given pathname
6
- * @param {string} pathname the pathname
7
- * @param {string} locale the site data to include in the rewrite
8
- * @returns {string} the rewrite path
9
- */
10
- function getLocaleRewrite(pathname, locale) {
11
- if (pathname === '/')
12
- return `/${locale}`;
13
- const path = pathname.startsWith('/') ? pathname : '/' + pathname;
14
- return `/${locale}${path}`;
15
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLocaleRewrite = getLocaleRewrite;
4
+ /**
5
+ * Get a locale rewrite path for given pathname
6
+ * @param {string} pathname the pathname
7
+ * @param {string} locale the site data to include in the rewrite
8
+ * @returns {string} the rewrite path
9
+ * @public
10
+ */
11
+ function getLocaleRewrite(pathname, locale) {
12
+ if (pathname === '/')
13
+ return `/${locale}`;
14
+ const path = pathname.startsWith('/') ? pathname : '/' + pathname;
15
+ return `/${locale}${path}`;
16
+ }