@esri/solutions-components 0.3.5 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. package/dist/cjs/buffer-tools_6.cjs.entry.js +26 -8
  2. package/dist/cjs/calcite-combobox_3.cjs.entry.js +2 -2
  3. package/dist/cjs/calcite-input-message_5.cjs.entry.js +6 -4
  4. package/dist/cjs/calcite-shell-panel_14.cjs.entry.js +2 -2
  5. package/dist/cjs/{csvUtils-83af7ae1.js → csvUtils-34666909.js} +1 -1
  6. package/dist/cjs/{interfaces-772edf61.js → interfaces-17c631bf.js} +1 -1
  7. package/dist/cjs/layer-table.cjs.entry.js +3 -3
  8. package/dist/cjs/loader.cjs.js +1 -1
  9. package/dist/cjs/map-card.cjs.entry.js +1 -1
  10. package/dist/cjs/{mapViewUtils-55ac76cb.js → mapViewUtils-24d1d859.js} +1 -1
  11. package/dist/cjs/public-notification.cjs.entry.js +41 -7
  12. package/dist/cjs/solution-configuration.cjs.entry.js +2 -2
  13. package/dist/cjs/solution-contents_3.cjs.entry.js +2 -2
  14. package/dist/cjs/{solution-store-39726b81.js → solution-store-2dbab624.js} +1 -1
  15. package/dist/cjs/solutions-components.cjs.js +1 -1
  16. package/dist/collection/components/buffer-tools/buffer-tools.js +48 -0
  17. package/dist/collection/components/map-draw-tools/map-draw-tools.js +10 -4
  18. package/dist/collection/components/public-notification/public-notification.css +12 -12
  19. package/dist/collection/components/public-notification/public-notification.js +50 -4
  20. package/dist/collection/components/refine-selection/refine-selection.js +4 -2
  21. package/dist/collection/components/refine-selection-tools/refine-selection-tools.css +1 -0
  22. package/dist/collection/components/refine-selection-tools/refine-selection-tools.js +3 -1
  23. package/dist/collection/demos/new-public-notification.html +7 -6
  24. package/dist/collection/utils/interfaces.js +1 -1
  25. package/dist/collection/utils/interfaces.ts +7 -2
  26. package/dist/components/buffer-tools2.js +10 -0
  27. package/dist/components/interfaces3.js +1 -1
  28. package/dist/components/map-draw-tools2.js +10 -4
  29. package/dist/components/public-notification.js +40 -6
  30. package/dist/components/refine-selection-tools2.js +4 -2
  31. package/dist/components/refine-selection2.js +4 -2
  32. package/dist/esm/buffer-tools_6.entry.js +26 -8
  33. package/dist/esm/calcite-combobox_3.entry.js +2 -2
  34. package/dist/esm/calcite-input-message_5.entry.js +6 -4
  35. package/dist/esm/calcite-shell-panel_14.entry.js +2 -2
  36. package/dist/esm/{csvUtils-eb231cfb.js → csvUtils-ae3004b9.js} +1 -1
  37. package/dist/esm/{interfaces-3b23a5f9.js → interfaces-d0d83efa.js} +1 -1
  38. package/dist/esm/layer-table.entry.js +3 -3
  39. package/dist/esm/loader.js +1 -1
  40. package/dist/esm/map-card.entry.js +1 -1
  41. package/dist/esm/{mapViewUtils-e5d8a1e1.js → mapViewUtils-541e7a3c.js} +1 -1
  42. package/dist/esm/public-notification.entry.js +41 -7
  43. package/dist/esm/solution-configuration.entry.js +2 -2
  44. package/dist/esm/solution-contents_3.entry.js +2 -2
  45. package/dist/esm/{solution-store-c0bf9200.js → solution-store-41e15f1c.js} +1 -1
  46. package/dist/esm/solutions-components.js +1 -1
  47. package/dist/solutions-components/demos/new-public-notification.html +7 -6
  48. package/dist/solutions-components/p-05e64bd1.js +498 -2
  49. package/dist/solutions-components/p-08a95b33.entry.js +138 -0
  50. package/dist/solutions-components/p-0da5bbdf.entry.js +91 -0
  51. package/dist/solutions-components/p-0ef91144.entry.js +913 -0
  52. package/dist/solutions-components/p-0f523243.entry.js +1916 -0
  53. package/dist/solutions-components/p-11b9510e.entry.js +173 -0
  54. package/dist/solutions-components/p-1b875d94.entry.js +58 -0
  55. package/dist/solutions-components/p-1c567f3a.js +23 -16
  56. package/dist/solutions-components/p-1c883db9.entry.js +43 -0
  57. package/dist/solutions-components/p-1f225056.js +322 -0
  58. package/dist/solutions-components/p-1f499e67.entry.js +72 -0
  59. package/dist/solutions-components/p-20d3d758.entry.js +881 -0
  60. package/dist/solutions-components/p-2274ac9e.entry.js +160 -0
  61. package/dist/solutions-components/p-23ec5ac5.entry.js +93 -0
  62. package/dist/solutions-components/p-2447798c.entry.js +155 -0
  63. package/dist/solutions-components/p-2525e691.entry.js +432 -0
  64. package/dist/solutions-components/p-2561f5b5.js +4092 -0
  65. package/dist/solutions-components/p-29f887c0.entry.js +234 -0
  66. package/dist/solutions-components/p-2a0d8047.entry.js +345 -0
  67. package/dist/solutions-components/p-2c177e6a.entry.js +101 -0
  68. package/dist/solutions-components/p-2e9ed892.js +46 -1
  69. package/dist/solutions-components/p-316f56db.js +219 -2
  70. package/dist/solutions-components/p-327f3ebf.entry.js +98 -0
  71. package/dist/solutions-components/p-356f8b54.entry.js +138 -0
  72. package/dist/solutions-components/p-359c58de.entry.js +172 -0
  73. package/dist/solutions-components/p-37336c0d.entry.js +116 -0
  74. package/dist/solutions-components/p-374a5031.js +105 -2
  75. package/dist/solutions-components/p-39ea6ef4.entry.js +71 -0
  76. package/dist/solutions-components/p-3b010ce1.js +17 -1
  77. package/dist/solutions-components/p-4307dacd.js +194 -1
  78. package/dist/solutions-components/p-44da2507.js +405 -14
  79. package/dist/solutions-components/p-46bdffe8.entry.js +54 -0
  80. package/dist/solutions-components/p-4894bbeb.js +53 -2
  81. package/dist/solutions-components/p-4cd569f1.entry.js +1298 -0
  82. package/dist/solutions-components/p-4d4160f9.entry.js +121 -0
  83. package/dist/solutions-components/p-4e32bf8c.js +482 -1
  84. package/dist/solutions-components/p-4e9cbd32.entry.js +184 -0
  85. package/dist/solutions-components/p-508317b3.js +13 -2
  86. package/dist/solutions-components/p-54697d58.entry.js +198 -0
  87. package/dist/solutions-components/p-55c79103.entry.js +311 -0
  88. package/dist/solutions-components/p-57fd19c0.entry.js +706 -0
  89. package/dist/solutions-components/p-59b48fde.entry.js +443 -0
  90. package/dist/solutions-components/p-60e0e6a0.entry.js +214 -0
  91. package/dist/solutions-components/p-621d0534.entry.js +123 -0
  92. package/dist/solutions-components/p-63f6e8f1.js +14 -1
  93. package/dist/solutions-components/p-66aeec57.entry.js +61 -0
  94. package/dist/solutions-components/p-69834f46.entry.js +618 -0
  95. package/dist/solutions-components/p-6d9da8e5.entry.js +21530 -0
  96. package/dist/solutions-components/p-6e0da576.js +13 -1
  97. package/dist/solutions-components/p-6ec3f294.entry.js +106 -0
  98. package/dist/solutions-components/p-6fe17794.js +9 -1
  99. package/dist/solutions-components/p-7024cb16.entry.js +72 -0
  100. package/dist/solutions-components/p-70535506.entry.js +226 -0
  101. package/dist/solutions-components/p-708a63a8.js +12 -1
  102. package/dist/solutions-components/p-729708a3.js +14 -1
  103. package/dist/solutions-components/p-73e23995.js +6 -1
  104. package/dist/solutions-components/p-74b29d75.entry.js +231 -0
  105. package/dist/solutions-components/p-74b7ee25.entry.js +711 -0
  106. package/dist/solutions-components/p-77182c3a.js +3015 -1
  107. package/dist/solutions-components/p-78b3ef80.entry.js +456 -0
  108. package/dist/solutions-components/p-79709c19.js +60 -3
  109. package/dist/solutions-components/p-7a46ef97.js +181 -2
  110. package/dist/solutions-components/p-7be159e6.entry.js +175 -0
  111. package/dist/solutions-components/p-7d4451c2.entry.js +71 -0
  112. package/dist/solutions-components/p-7daea1df.js +41 -1
  113. package/dist/solutions-components/p-7e39e5ad.entry.js +102 -0
  114. package/dist/solutions-components/p-7fb45059.entry.js +43 -0
  115. package/dist/solutions-components/p-815533de.js +306 -3
  116. package/dist/solutions-components/p-816622ca.entry.js +248 -0
  117. package/dist/solutions-components/p-83166522.js +205 -2
  118. package/dist/solutions-components/p-83bd1991.entry.js +36 -0
  119. package/dist/solutions-components/p-856464d7.entry.js +572 -0
  120. package/dist/solutions-components/p-8c349bad.entry.js +347 -0
  121. package/dist/solutions-components/p-8dccb390.entry.js +1986 -0
  122. package/dist/solutions-components/p-904c185a.entry.js +228 -0
  123. package/dist/solutions-components/p-9092f8b3.entry.js +156 -0
  124. package/dist/solutions-components/p-9371145a.entry.js +477 -0
  125. package/dist/solutions-components/p-93d3119d.js +1948 -1
  126. package/dist/solutions-components/p-95ec8062.entry.js +173 -0
  127. package/dist/solutions-components/p-991ee695.js +109 -1
  128. package/dist/solutions-components/p-9a57dab7.entry.js +213 -0
  129. package/dist/solutions-components/p-9a9955db.js +41 -1
  130. package/dist/solutions-components/p-9c1ebc90.js +35 -16
  131. package/dist/solutions-components/p-9eba5c66.js +399 -3
  132. package/dist/solutions-components/p-a033a507.entry.js +252 -0
  133. package/dist/solutions-components/p-a3773415.entry.js +1132 -0
  134. package/dist/solutions-components/p-a44fe40f.entry.js +94 -0
  135. package/dist/solutions-components/p-a5b1ab03.js +33 -3
  136. package/dist/solutions-components/p-a5b2c13d.entry.js +723 -0
  137. package/dist/solutions-components/p-a6d729b7.entry.js +85 -0
  138. package/dist/solutions-components/p-a8005026.entry.js +565 -0
  139. package/dist/solutions-components/p-a80b3880.js +14 -1
  140. package/dist/solutions-components/p-a89198a3.entry.js +2620 -0
  141. package/dist/solutions-components/p-aa04bd1f.entry.js +95 -0
  142. package/dist/solutions-components/p-aa0a0922.entry.js +80 -0
  143. package/dist/solutions-components/p-ae1fd76b.js +11 -1
  144. package/dist/solutions-components/p-b2cf435e.entry.js +87 -0
  145. package/dist/solutions-components/p-b359dc78.js +41 -1
  146. package/dist/solutions-components/p-b57bc4eb.entry.js +71 -0
  147. package/dist/solutions-components/p-b75cc407.entry.js +145 -0
  148. package/dist/solutions-components/p-b911cb75.entry.js +71 -0
  149. package/dist/solutions-components/p-b965e177.entry.js +335 -0
  150. package/dist/solutions-components/p-b978636e.js +14 -1
  151. package/dist/solutions-components/p-ba10a5c8.entry.js +42 -0
  152. package/dist/solutions-components/p-bd67334c.js +122 -2
  153. package/dist/solutions-components/p-bde20dba.entry.js +212 -0
  154. package/dist/solutions-components/p-be0b5a94.entry.js +248 -0
  155. package/dist/solutions-components/p-c023e6a1.js +2028 -2
  156. package/dist/solutions-components/p-c27b0c2d.entry.js +150 -0
  157. package/dist/solutions-components/p-c579ed60.entry.js +447 -0
  158. package/dist/solutions-components/p-c92bc231.js +101 -2
  159. package/dist/solutions-components/p-cc815aca.js +839 -16
  160. package/dist/solutions-components/p-cc8beabb.entry.js +695 -0
  161. package/dist/solutions-components/p-cdc46c0c.js +1751 -2
  162. package/dist/solutions-components/p-d12e6992.entry.js +118 -0
  163. package/dist/solutions-components/p-d1dfed6b.entry.js +179 -0
  164. package/dist/solutions-components/p-d48a24e6.js +754 -2
  165. package/dist/solutions-components/p-d96ee3ef.entry.js +579 -0
  166. package/dist/solutions-components/p-dbc9a5a8.js +80 -0
  167. package/dist/solutions-components/p-dcdbe712.entry.js +278 -0
  168. package/dist/solutions-components/p-de39206f.entry.js +113 -0
  169. package/dist/solutions-components/p-de5416e8.js +28 -1
  170. package/dist/solutions-components/p-df420d54.entry.js +213 -0
  171. package/dist/solutions-components/p-e3138cf0.entry.js +20 -0
  172. package/dist/solutions-components/p-e4845fec.entry.js +152 -0
  173. package/dist/solutions-components/p-e611d8c8.js +28 -1
  174. package/dist/solutions-components/p-e947d3b0.js +5 -1
  175. package/dist/solutions-components/p-ea534300.js +41 -2
  176. package/dist/solutions-components/p-ec84ee85.entry.js +55 -0
  177. package/dist/solutions-components/p-ed36c637.entry.js +85 -0
  178. package/dist/solutions-components/p-f0add71c.js +74 -0
  179. package/dist/solutions-components/p-f42e014b.js +171 -2
  180. package/dist/solutions-components/p-fc02e7de.entry.js +308 -0
  181. package/dist/solutions-components/p-fc884dd6.js +28 -16
  182. package/dist/solutions-components/p-fcbfa59c.entry.js +181 -0
  183. package/dist/solutions-components/p-fdc5cf5f.entry.js +138 -0
  184. package/dist/solutions-components/solutions-components.esm.js +20 -1
  185. package/dist/solutions-components/utils/interfaces.ts +7 -2
  186. package/dist/types/components/buffer-tools/buffer-tools.d.ts +9 -1
  187. package/dist/types/components/public-notification/public-notification.d.ts +26 -0
  188. package/dist/types/components.d.ts +9 -1
  189. package/dist/types/preact.d.ts +3 -1
  190. package/dist/types/utils/interfaces.d.ts +4 -0
  191. package/package.json +1 -1
  192. package/dist/solutions-components/p-021432b8.entry.js +0 -12
  193. package/dist/solutions-components/p-03440b1e.entry.js +0 -11
  194. package/dist/solutions-components/p-0512635b.entry.js +0 -6
  195. package/dist/solutions-components/p-086ef115.entry.js +0 -29
  196. package/dist/solutions-components/p-0b4bf57f.entry.js +0 -6
  197. package/dist/solutions-components/p-0c088725.entry.js +0 -6
  198. package/dist/solutions-components/p-0f820c08.entry.js +0 -6
  199. package/dist/solutions-components/p-164780a0.entry.js +0 -6
  200. package/dist/solutions-components/p-179a68a0.entry.js +0 -6
  201. package/dist/solutions-components/p-184b5005.entry.js +0 -11
  202. package/dist/solutions-components/p-1d082fee.entry.js +0 -11
  203. package/dist/solutions-components/p-1e6c02a2.entry.js +0 -11
  204. package/dist/solutions-components/p-20a58e62.entry.js +0 -17
  205. package/dist/solutions-components/p-20b2458c.entry.js +0 -11
  206. package/dist/solutions-components/p-245d47c1.entry.js +0 -6
  207. package/dist/solutions-components/p-2cb057a9.entry.js +0 -11
  208. package/dist/solutions-components/p-2cc72806.entry.js +0 -23
  209. package/dist/solutions-components/p-2de1db9c.entry.js +0 -11
  210. package/dist/solutions-components/p-2e9c7055.entry.js +0 -11
  211. package/dist/solutions-components/p-2ed5e6c8.entry.js +0 -11
  212. package/dist/solutions-components/p-3109d940.entry.js +0 -6
  213. package/dist/solutions-components/p-31a8bcfa.entry.js +0 -6
  214. package/dist/solutions-components/p-3f88ba73.entry.js +0 -6
  215. package/dist/solutions-components/p-3fa9b3c8.js +0 -36
  216. package/dist/solutions-components/p-40c41709.entry.js +0 -6
  217. package/dist/solutions-components/p-40e963c7.entry.js +0 -11
  218. package/dist/solutions-components/p-40f480da.entry.js +0 -11
  219. package/dist/solutions-components/p-49d5d2d3.entry.js +0 -11
  220. package/dist/solutions-components/p-4f7049a4.entry.js +0 -11
  221. package/dist/solutions-components/p-506e4d78.entry.js +0 -6
  222. package/dist/solutions-components/p-576fdcab.entry.js +0 -6
  223. package/dist/solutions-components/p-5bd0cf34.entry.js +0 -23
  224. package/dist/solutions-components/p-65e177f1.entry.js +0 -6
  225. package/dist/solutions-components/p-67d710c2.entry.js +0 -6
  226. package/dist/solutions-components/p-7268b445.entry.js +0 -11
  227. package/dist/solutions-components/p-75ea4667.entry.js +0 -6
  228. package/dist/solutions-components/p-778c0a36.entry.js +0 -17
  229. package/dist/solutions-components/p-7a22509b.entry.js +0 -12
  230. package/dist/solutions-components/p-7bff51db.entry.js +0 -6
  231. package/dist/solutions-components/p-7d2d0d5d.entry.js +0 -6
  232. package/dist/solutions-components/p-7f0036f1.entry.js +0 -11
  233. package/dist/solutions-components/p-8060fb94.entry.js +0 -6
  234. package/dist/solutions-components/p-80a1b305.entry.js +0 -6
  235. package/dist/solutions-components/p-81eae877.entry.js +0 -12
  236. package/dist/solutions-components/p-84e86b8b.entry.js +0 -6
  237. package/dist/solutions-components/p-877dd0dc.entry.js +0 -18
  238. package/dist/solutions-components/p-9106950a.entry.js +0 -11
  239. package/dist/solutions-components/p-979804a4.entry.js +0 -11
  240. package/dist/solutions-components/p-9862baa8.entry.js +0 -11
  241. package/dist/solutions-components/p-9b5a9117.entry.js +0 -12
  242. package/dist/solutions-components/p-9deff0c2.entry.js +0 -6
  243. package/dist/solutions-components/p-9f400eeb.entry.js +0 -6
  244. package/dist/solutions-components/p-a0639ad1.entry.js +0 -11
  245. package/dist/solutions-components/p-a33c044e.entry.js +0 -6
  246. package/dist/solutions-components/p-a516c658.entry.js +0 -6
  247. package/dist/solutions-components/p-aa0ef36d.entry.js +0 -11
  248. package/dist/solutions-components/p-aaccbdf3.entry.js +0 -18
  249. package/dist/solutions-components/p-ab03a5c9.entry.js +0 -11
  250. package/dist/solutions-components/p-ad469b92.entry.js +0 -11
  251. package/dist/solutions-components/p-adc86ac3.entry.js +0 -6
  252. package/dist/solutions-components/p-addc1156.entry.js +0 -11
  253. package/dist/solutions-components/p-ae846934.entry.js +0 -11
  254. package/dist/solutions-components/p-b0572fc4.entry.js +0 -37
  255. package/dist/solutions-components/p-b4e476b7.js +0 -257
  256. package/dist/solutions-components/p-b668daf8.js +0 -21
  257. package/dist/solutions-components/p-b6e6eae1.entry.js +0 -6
  258. package/dist/solutions-components/p-bc317a7f.entry.js +0 -6
  259. package/dist/solutions-components/p-bd4d0773.entry.js +0 -6
  260. package/dist/solutions-components/p-be41429f.js +0 -21
  261. package/dist/solutions-components/p-bf6b6353.entry.js +0 -11
  262. package/dist/solutions-components/p-c2e3dfbb.entry.js +0 -11
  263. package/dist/solutions-components/p-c4afae53.entry.js +0 -12
  264. package/dist/solutions-components/p-c9da1c26.entry.js +0 -6
  265. package/dist/solutions-components/p-cbf8cd49.entry.js +0 -6
  266. package/dist/solutions-components/p-cc1a064a.entry.js +0 -11
  267. package/dist/solutions-components/p-d09a168c.entry.js +0 -6
  268. package/dist/solutions-components/p-d377f913.entry.js +0 -11
  269. package/dist/solutions-components/p-d4cefead.entry.js +0 -37
  270. package/dist/solutions-components/p-d7bc0baf.entry.js +0 -16
  271. package/dist/solutions-components/p-d8968487.entry.js +0 -11
  272. package/dist/solutions-components/p-e00a0b86.entry.js +0 -11
  273. package/dist/solutions-components/p-e9a7ed49.entry.js +0 -11
  274. package/dist/solutions-components/p-ec27e493.entry.js +0 -11
  275. package/dist/solutions-components/p-ed6404eb.entry.js +0 -6
  276. package/dist/solutions-components/p-ef21e195.entry.js +0 -23
  277. package/dist/solutions-components/p-f6068a2d.entry.js +0 -11
  278. package/dist/solutions-components/p-f6c4cff3.entry.js +0 -11
  279. package/dist/solutions-components/p-f847291f.entry.js +0 -6
  280. package/dist/solutions-components/p-f90fd262.entry.js +0 -11
  281. package/dist/solutions-components/p-fc973005.entry.js +0 -6
  282. package/dist/solutions-components/p-ff9fb6bc.entry.js +0 -11
@@ -0,0 +1,1986 @@
1
+ /*!
2
+ * Copyright 2022 Esri
3
+ * Licensed under the Apache License, Version 2.0
4
+ * http://www.apache.org/licenses/LICENSE-2.0
5
+ */
6
+ import { r as registerInstance, h, H as Host, g as getElement } from './p-c023e6a1.js';
7
+ import { r as request, N as NODEJS_DEFAULT_REFERER_HEADER, c as cleanUrl, e as encodeQueryString, A as ArcGISAuthError, g as getProp, s as state } from './p-2561f5b5.js';
8
+ import { g as getLocaleComponentStrings } from './p-44da2507.js';
9
+ import './p-4307dacd.js';
10
+ import './p-dbc9a5a8.js';
11
+ import './p-3b010ce1.js';
12
+
13
+ /** @license
14
+ * Copyright 2022 Esri
15
+ *
16
+ * Licensed under the Apache License, Version 2.0 (the "License");
17
+ * you may not use this file except in compliance with the License.
18
+ * You may obtain a copy of the License at
19
+ *
20
+ * http://www.apache.org/licenses/LICENSE-2.0
21
+ *
22
+ * Unless required by applicable law or agreed to in writing, software
23
+ * distributed under the License is distributed on an "AS IS" BASIS,
24
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+ * See the License for the specific language governing permissions and
26
+ * limitations under the License.
27
+ */
28
+ //--------------------------------------------------------------------------
29
+ //
30
+ // Public Functions
31
+ //
32
+ //--------------------------------------------------------------------------
33
+ /**
34
+ * Sort the solution items
35
+ *
36
+ * @param templates a list of item templates from the solution
37
+ *
38
+ * @returns a sorted list of solution items
39
+ */
40
+ function getInventoryItems(templates) {
41
+ const hierarchy = getItemHierarchy(templates);
42
+ const ids = hierarchy.reduce((prev, cur) => {
43
+ prev.push(cur.id);
44
+ return prev;
45
+ }, []);
46
+ return templates.reduce((prev, cur) => {
47
+ if (ids.indexOf(cur.itemId) > -1) {
48
+ const hierarchyItems = hierarchy.filter(hi => hi.id === cur.itemId);
49
+ prev.push(_getItemFromTemplate(cur, templates, hierarchyItems[0].dependencies));
50
+ }
51
+ return prev;
52
+ }, []);
53
+ }
54
+ /**
55
+ * Create item hierarchy that will avoid issues from cylical dependencies
56
+ *
57
+ * @param templates a list of item templates from the solution
58
+ *
59
+ * @returns a hierarchy for item and item dependency display
60
+ */
61
+ function getItemHierarchy(templates) {
62
+ const hierarchy = [];
63
+ // Get the template specified by id out of a list of templates
64
+ function getTemplateInSolution(templates, id) {
65
+ const iTemplate = templates.findIndex((template) => id === template.itemId);
66
+ return iTemplate >= 0 ? templates[iTemplate] : null;
67
+ }
68
+ // Hierarchically list the dependencies of specified node
69
+ function traceItemId(id, accumulatedHierarchy, alreadyVisitedIds = []) {
70
+ // Get the dependencies of the node
71
+ const template = getTemplateInSolution(templates, id);
72
+ /* istanbul ignore else */
73
+ if (template) {
74
+ const templateEntry = {
75
+ id,
76
+ dependencies: []
77
+ };
78
+ // Visit each dependency, but only if this template is not in the alreadyVisitedIds list to avoid infinite loops
79
+ /* istanbul ignore else */
80
+ if (alreadyVisitedIds.indexOf(id) < 0) {
81
+ // Add dependency to alreadyVisitedIds list
82
+ alreadyVisitedIds.push(id);
83
+ template.dependencies.forEach((dependencyId) => {
84
+ // Remove dependency from list of templates to visit in the top-level loop
85
+ const iDependencyTemplate = templateItemIds.indexOf(dependencyId);
86
+ /* istanbul ignore else */
87
+ if (iDependencyTemplate >= 0) {
88
+ templateItemIds.splice(iDependencyTemplate, 1);
89
+ }
90
+ traceItemId(dependencyId, templateEntry.dependencies, alreadyVisitedIds);
91
+ });
92
+ }
93
+ accumulatedHierarchy.push(templateEntry);
94
+ }
95
+ }
96
+ // Start with top-level nodes and add in the rest of the nodes to catch cycles without top-level nodes
97
+ let templateItemIds = _getTopLevelItemIds(templates);
98
+ const otherItems = templates
99
+ .filter((template) => templateItemIds.indexOf(template.itemId) < 0) // only keep non-top-level nodes
100
+ .sort((a, b) => b.dependencies.length - a.dependencies.length); // sort so that nodes with more dependencies come first--reduces stubs
101
+ templateItemIds = templateItemIds.concat(otherItems.map((template) => template.itemId));
102
+ // Step through the list of nodes; we'll also remove nodes as we visit them
103
+ let itemId = templateItemIds.shift();
104
+ while (typeof itemId !== "undefined") {
105
+ traceItemId(itemId, hierarchy);
106
+ itemId = templateItemIds.shift();
107
+ }
108
+ return hierarchy;
109
+ }
110
+ /**
111
+ * Explore the solution item templates for variables we will allow users to insert at runtime
112
+ *
113
+ * @param templates a list of item templates from the solution
114
+ * @param translations nls translation object
115
+ *
116
+ * @returns a list of variables from the solution item templates
117
+ */
118
+ function getSolutionVariables(templates, translations) {
119
+ const vars = [];
120
+ templates.forEach(t => {
121
+ const item = {
122
+ id: t.itemId,
123
+ title: t.item.title || t.item.name,
124
+ type: t.type,
125
+ value: undefined,
126
+ dependencies: [{
127
+ id: t.itemId,
128
+ title: translations.itemId,
129
+ value: `{{${t.itemId}.itemId}}`,
130
+ }]
131
+ };
132
+ if (t.item.url) {
133
+ item.dependencies.push({
134
+ id: t.itemId,
135
+ title: translations.url,
136
+ value: `{{${t.itemId}.url}}`,
137
+ });
138
+ }
139
+ if (t.type === "Feature Service") {
140
+ // TODO need to set source service name var...
141
+ // TODO need to set soure service shape field name "{{d05b3cf1ffcb4a4fa677627dfb18609e.name}}.Shape"
142
+ item.dependencies.push({
143
+ id: t.itemId,
144
+ title: translations.solutionExtent,
145
+ value: `{{${t.itemId}.solutionExtent}}`,
146
+ });
147
+ _addLayersOrTables(t.properties.layers || [], item, t, translations);
148
+ _addLayersOrTables(t.properties.tables || [], item, t, translations);
149
+ }
150
+ vars.push(item);
151
+ });
152
+ return vars;
153
+ }
154
+ /**
155
+ * Set key organization variables we will allow users to insert at runtime
156
+ *
157
+ * @param translations nls translation object
158
+ *
159
+ * @returns a list of variables for the organization
160
+ */
161
+ function getOrganizationVariables(translations) {
162
+ const orgVars = [{
163
+ id: "",
164
+ title: translations.geocodeUrl,
165
+ value: "{{organization.helperServices.geocode:getDefaultLocatorURL}}"
166
+ }, {
167
+ id: "",
168
+ title: translations.geometryUrl,
169
+ value: "{{organization.helperServices.geometry.url}}"
170
+ }, {
171
+ id: "",
172
+ title: translations.portalBaseUrl,
173
+ value: "{{portalBaseUrl}}"
174
+ }, {
175
+ id: "",
176
+ title: translations.routeUrl,
177
+ value: "{{organization.helperServices.route.url}}"
178
+ }, {
179
+ id: "",
180
+ title: translations.solutionItemExtent,
181
+ value: "{{solutionItemExtent}}"
182
+ }];
183
+ return orgVars;
184
+ }
185
+ //--------------------------------------------------------------------------
186
+ //
187
+ // Private Functions
188
+ //
189
+ //--------------------------------------------------------------------------
190
+ /**
191
+ * Explore a solution item template for variables we will allow users to insert at runtime.
192
+ * This function will update the item argument that is passed in with the var details.
193
+ *
194
+ * @param children a list of layers or tables from a template
195
+ * @param item an object that store key details for a given variable
196
+ * @param template one of the templates from the current solution
197
+ * @param translations nls translations object
198
+ *
199
+ */
200
+ function _addLayersOrTables(children, item, template, translations) {
201
+ children.forEach(l => {
202
+ const name = l.name && l.name.indexOf("||") > -1 ? l.name.split("||")[1].replace("}}", "").trim() : l.name;
203
+ item.dependencies.push({
204
+ id: template.itemId,
205
+ title: `${name} (${translations.id})`,
206
+ value: `{{${template.itemId}.layer${l.id}.id}}`,
207
+ });
208
+ item.dependencies.push({
209
+ id: template.itemId,
210
+ title: `${name} (${translations.name})`,
211
+ value: `{{${template.itemId}.layer${l.id}.name||${name}}}`,
212
+ });
213
+ });
214
+ }
215
+ /**
216
+ * Capture key details from the solution item template
217
+ *
218
+ * @param template one of the templates from the current solution
219
+ * @param templates full list of templates
220
+ * @param dependencies list of hierarchical dependencies
221
+ *
222
+ * @returns an IInventoryItem that is used by other components to work with this template
223
+ */
224
+ function _getItemFromTemplate(template, templates, dependencies) {
225
+ return {
226
+ id: template.itemId || "",
227
+ title: template.item.title || "",
228
+ dependencies: _getDependencies(dependencies, templates),
229
+ type: template.item.type || "",
230
+ typeKeywords: template.item.typeKeywords || [] /*,
231
+ solutionItem: {
232
+ itemId: template.itemId,
233
+ itemDetails: _getItemDetails(template.item, template.type === "Group"),
234
+ isResource: _getIsResource(template),
235
+ data: template.data,
236
+ properties: template.properties,
237
+ type: template.type,
238
+ groupDetails: _getGroupDetails(template, templates)
239
+ }*/
240
+ };
241
+ }
242
+ /**
243
+ * Capture key details from the solution item template
244
+ *
245
+ * @param dependencies list of dependencies from a template
246
+ * @param templates full list of templates
247
+ *
248
+ * @returns a list of IInventoryItem that are used by other components to work with the templates
249
+ */
250
+ function _getDependencies(dependencies, templates) {
251
+ const dependencyItems = [];
252
+ const depIds = dependencies.reduce((prev, cur) => {
253
+ prev.push(cur.id);
254
+ dependencyItems.push(cur);
255
+ return prev;
256
+ }, []);
257
+ return templates.reduce((prev, curr) => {
258
+ const i = depIds.indexOf(curr.itemId);
259
+ if (i > -1) {
260
+ prev.push(_getItemFromTemplate(curr, templates, dependencyItems[i].dependencies));
261
+ }
262
+ return prev;
263
+ }, []);
264
+ }
265
+ /**
266
+ * Capture the key item details for a given template
267
+ *
268
+ * @param item the templates item
269
+ * @param isGroup boolean to indicate if the item is a group
270
+ * @param itemId the item id of the template
271
+ *
272
+ * @returns a IItemDetails object for the current item
273
+ */
274
+ /*
275
+ function _getItemDetails(
276
+ item: any,
277
+ isGroup: boolean
278
+ ): IItemDetails {
279
+ return {
280
+ title: item.title || "",
281
+ snippet: item.snippet || "",
282
+ description: item.description || "",
283
+ tags: item.tags || [],
284
+ accessInformation: !isGroup ? item.accessInformation || "" : "",
285
+ licenseInfo: !isGroup ? item.licenseInfo || "" : ""
286
+ };
287
+ }
288
+ */
289
+ /**
290
+ * Capture the key item details for a given group template
291
+ *
292
+ * @param template one of the templates from the current solution
293
+ * @param templates full list of templates
294
+ *
295
+ * @returns a list of IItemShare objects
296
+ */
297
+ /*
298
+ function _getGroupDetails(
299
+ template: any,
300
+ templates: any[]
301
+ ): IItemShare[] {
302
+ return template.type === "Group" ? templates.reduce((prev, cur) => {
303
+ if (cur.itemId !== template.itemId && cur.type !== "Group") {
304
+ prev.push({
305
+ id: cur.itemId,
306
+ title: cur.item.name || cur.item.title,
307
+ isShared: (cur.groups || []).indexOf(template.itemId) > -1,
308
+ shareItem: (cur.groups || []).indexOf(template.itemId) > -1,
309
+ type: cur.type,
310
+ typeKeywords: cur.item.typeKeywords
311
+ });
312
+ }
313
+ return prev;
314
+ }, []) : [];
315
+ }
316
+ */
317
+ /**
318
+ * Used to understand if we are dealing with a binary object that will support upload/download
319
+ *
320
+ * @param template one of the templates from the current solution
321
+ *
322
+ * @returns true if this item supports upload/download
323
+ */
324
+ /*
325
+ function _getIsResource(
326
+ template: any
327
+ ): boolean {
328
+ return template.type !== "Group" && template.resources.some(r => r.indexOf("_info_thumbnail") < 0) &&
329
+ (template.data === null || JSON.stringify(template.data) === "{}");
330
+ }
331
+ */
332
+ /**
333
+ * Sort the template ids based on their dependencies
334
+ *
335
+ * @param templates full list of templates
336
+ *
337
+ * @returns a list of Itop level item ids
338
+ */
339
+ function _getTopLevelItemIds(templates) {
340
+ // Find the top-level nodes. Start with all nodes, then remove those that other nodes depend on
341
+ const topLevelItemCandidateIds = templates.map((template) => template.itemId);
342
+ templates.forEach((template) => {
343
+ (template.dependencies || []).forEach((dependencyId) => {
344
+ const iNode = topLevelItemCandidateIds.indexOf(dependencyId);
345
+ if (iNode >= 0) {
346
+ // Node is somebody's dependency, so remove the node from the list of top-level nodes
347
+ // If iNode == -1, then it's a shared dependency and it has already been removed
348
+ topLevelItemCandidateIds.splice(iNode, 1);
349
+ }
350
+ });
351
+ });
352
+ return topLevelItemCandidateIds;
353
+ }
354
+
355
+ /* Copyright (c) 2017-2020 Environmental Systems Research Institute, Inc.
356
+ * Apache-2.0 */
357
+ function decodeParam(param) {
358
+ var _a = param.split("="), key = _a[0], value = _a[1];
359
+ return { key: decodeURIComponent(key), value: decodeURIComponent(value) };
360
+ }
361
+ /**
362
+ * Decodes the passed query string as an object.
363
+ *
364
+ * @param query A string to be decoded.
365
+ * @returns A decoded query param object.
366
+ */
367
+ function decodeQueryString(query) {
368
+ return query
369
+ .replace(/^#/, "")
370
+ .split("&")
371
+ .reduce(function (acc, entry) {
372
+ var _a = decodeParam(entry), key = _a.key, value = _a.value;
373
+ acc[key] = value;
374
+ return acc;
375
+ }, {});
376
+ }
377
+
378
+ /*! *****************************************************************************
379
+ Copyright (c) Microsoft Corporation.
380
+
381
+ Permission to use, copy, modify, and/or distribute this software for any
382
+ purpose with or without fee is hereby granted.
383
+
384
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
385
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
386
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
387
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
388
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
389
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
390
+ PERFORMANCE OF THIS SOFTWARE.
391
+ ***************************************************************************** */
392
+
393
+ var __assign = function() {
394
+ __assign = Object.assign || function __assign(t) {
395
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
396
+ s = arguments[i];
397
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
398
+ }
399
+ return t;
400
+ };
401
+ return __assign.apply(this, arguments);
402
+ };
403
+
404
+ /* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
405
+ * Apache-2.0 */
406
+ function fetchToken(url, requestOptions) {
407
+ var options = requestOptions;
408
+ // we generate a response, so we can't return the raw response
409
+ options.rawResponse = false;
410
+ return request(url, options).then(function (response) {
411
+ var r = {
412
+ token: response.access_token,
413
+ username: response.username,
414
+ expires: new Date(
415
+ // convert seconds in response to milliseconds and add the value to the current time to calculate a static expiration timestamp
416
+ Date.now() + (response.expires_in * 1000 - 1000)),
417
+ ssl: response.ssl === true
418
+ };
419
+ if (response.refresh_token) {
420
+ r.refreshToken = response.refresh_token;
421
+ }
422
+ return r;
423
+ });
424
+ }
425
+
426
+ /* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
427
+ * Apache-2.0 */
428
+ function generateToken(url, requestOptions) {
429
+ var options = requestOptions;
430
+ /* istanbul ignore else */
431
+ if (typeof window !== "undefined" &&
432
+ window.location &&
433
+ window.location.host) {
434
+ options.params.referer = window.location.host;
435
+ }
436
+ else {
437
+ options.params.referer = NODEJS_DEFAULT_REFERER_HEADER;
438
+ }
439
+ return request(url, options);
440
+ }
441
+
442
+ /**
443
+ * Used to test if a URL is an ArcGIS Online URL
444
+ */
445
+ var arcgisOnlineUrlRegex = /^https?:\/\/(\S+)\.arcgis\.com.+/;
446
+ function isOnline(url) {
447
+ return arcgisOnlineUrlRegex.test(url);
448
+ }
449
+ function normalizeOnlinePortalUrl(portalUrl) {
450
+ if (!arcgisOnlineUrlRegex.test(portalUrl)) {
451
+ return portalUrl;
452
+ }
453
+ switch (getOnlineEnvironment(portalUrl)) {
454
+ case "dev":
455
+ return "https://devext.arcgis.com/sharing/rest";
456
+ case "qa":
457
+ return "https://qaext.arcgis.com/sharing/rest";
458
+ default:
459
+ return "https://www.arcgis.com/sharing/rest";
460
+ }
461
+ }
462
+ function getOnlineEnvironment(url) {
463
+ if (!arcgisOnlineUrlRegex.test(url)) {
464
+ return null;
465
+ }
466
+ var match = url.match(arcgisOnlineUrlRegex);
467
+ var subdomain = match[1].split(".").pop();
468
+ if (subdomain.includes("dev")) {
469
+ return "dev";
470
+ }
471
+ if (subdomain.includes("qa")) {
472
+ return "qa";
473
+ }
474
+ return "production";
475
+ }
476
+ function isFederated(owningSystemUrl, portalUrl) {
477
+ var normalizedPortalUrl = cleanUrl(normalizeOnlinePortalUrl(portalUrl)).replace(/https?:\/\//, "");
478
+ var normalizedOwningSystemUrl = cleanUrl(owningSystemUrl).replace(/https?:\/\//, "");
479
+ return new RegExp(normalizedOwningSystemUrl, "i").test(normalizedPortalUrl);
480
+ }
481
+ function canUseOnlineToken(portalUrl, requestUrl) {
482
+ var portalIsOnline = isOnline(portalUrl);
483
+ var requestIsOnline = isOnline(requestUrl);
484
+ var portalEnv = getOnlineEnvironment(portalUrl);
485
+ var requestEnv = getOnlineEnvironment(requestUrl);
486
+ if (portalIsOnline && requestIsOnline && portalEnv === requestEnv) {
487
+ return true;
488
+ }
489
+ return false;
490
+ }
491
+
492
+ /* Copyright (c) 2018-2020 Environmental Systems Research Institute, Inc.
493
+ * Apache-2.0 */
494
+ /**
495
+ * Validates that the user has access to the application
496
+ * and if they user should be presented a "View Only" mode
497
+ *
498
+ * This is only needed/valid for Esri applications that are "licensed"
499
+ * and shipped in ArcGIS Online or ArcGIS Enterprise. Most custom applications
500
+ * should not need or use this.
501
+ *
502
+ * ```js
503
+ * import { validateAppAccess } from '@esri/arcgis-rest-auth';
504
+ *
505
+ * return validateAppAccess('your-token', 'theClientId')
506
+ * .then((result) => {
507
+ * if (!result.value) {
508
+ * // redirect or show some other ui
509
+ * } else {
510
+ * if (result.viewOnlyUserTypeApp) {
511
+ * // use this to inform your app to show a "View Only" mode
512
+ * }
513
+ * }
514
+ * })
515
+ * .catch((err) => {
516
+ * // two possible errors
517
+ * // invalid clientId: {"error":{"code":400,"messageCode":"GWM_0007","message":"Invalid request","details":[]}}
518
+ * // invalid token: {"error":{"code":498,"message":"Invalid token.","details":[]}}
519
+ * })
520
+ * ```
521
+ *
522
+ * Note: This is only usable by Esri applications hosted on *arcgis.com, *esri.com or within
523
+ * an ArcGIS Enterprise installation. Custom applications can not use this.
524
+ *
525
+ * @param token platform token
526
+ * @param clientId application client id
527
+ * @param portal Optional
528
+ */
529
+ function validateAppAccess(token, clientId, portal) {
530
+ if (portal === void 0) { portal = "https://www.arcgis.com/sharing/rest"; }
531
+ var url = portal + "/oauth2/validateAppAccess";
532
+ var ro = {
533
+ method: "POST",
534
+ params: {
535
+ f: "json",
536
+ client_id: clientId,
537
+ token: token,
538
+ },
539
+ };
540
+ return request(url, ro);
541
+ }
542
+
543
+ /* Copyright (c) 2017-2019 Environmental Systems Research Institute, Inc.
544
+ * Apache-2.0 */
545
+ function defer() {
546
+ var deferred = {
547
+ promise: null,
548
+ resolve: null,
549
+ reject: null,
550
+ };
551
+ deferred.promise = new Promise(function (resolve, reject) {
552
+ deferred.resolve = resolve;
553
+ deferred.reject = reject;
554
+ });
555
+ return deferred;
556
+ }
557
+ /**
558
+ * ```js
559
+ * import { UserSession } from '@esri/arcgis-rest-auth';
560
+ * UserSession.beginOAuth2({
561
+ * // register an app of your own to create a unique clientId
562
+ * clientId: "abc123",
563
+ * redirectUri: 'https://yourapp.com/authenticate.html'
564
+ * })
565
+ * .then(session)
566
+ * // or
567
+ * new UserSession({
568
+ * username: "jsmith",
569
+ * password: "123456"
570
+ * })
571
+ * // or
572
+ * UserSession.deserialize(cache)
573
+ * ```
574
+ * Used to authenticate both ArcGIS Online and ArcGIS Enterprise users. `UserSession` includes helper methods for [OAuth 2.0](/arcgis-rest-js/guides/browser-authentication/) in both browser and server applications.
575
+ */
576
+ var UserSession = /** @class */ (function () {
577
+ function UserSession(options) {
578
+ this.clientId = options.clientId;
579
+ this._refreshToken = options.refreshToken;
580
+ this._refreshTokenExpires = options.refreshTokenExpires;
581
+ this.username = options.username;
582
+ this.password = options.password;
583
+ this._token = options.token;
584
+ this._tokenExpires = options.tokenExpires;
585
+ this.portal = options.portal
586
+ ? cleanUrl(options.portal)
587
+ : "https://www.arcgis.com/sharing/rest";
588
+ this.ssl = options.ssl;
589
+ this.provider = options.provider || "arcgis";
590
+ this.tokenDuration = options.tokenDuration || 20160;
591
+ this.redirectUri = options.redirectUri;
592
+ this.refreshTokenTTL = options.refreshTokenTTL || 20160;
593
+ this.server = options.server;
594
+ this.federatedServers = {};
595
+ this.trustedDomains = [];
596
+ // if a non-federated server was passed explicitly, it should be trusted.
597
+ if (options.server) {
598
+ // if the url includes more than '/arcgis/', trim the rest
599
+ var root = this.getServerRootUrl(options.server);
600
+ this.federatedServers[root] = {
601
+ token: options.token,
602
+ expires: options.tokenExpires,
603
+ };
604
+ }
605
+ this._pendingTokenRequests = {};
606
+ }
607
+ Object.defineProperty(UserSession.prototype, "token", {
608
+ /**
609
+ * The current ArcGIS Online or ArcGIS Enterprise `token`.
610
+ */
611
+ get: function () {
612
+ return this._token;
613
+ },
614
+ enumerable: false,
615
+ configurable: true
616
+ });
617
+ Object.defineProperty(UserSession.prototype, "tokenExpires", {
618
+ /**
619
+ * The expiration time of the current `token`.
620
+ */
621
+ get: function () {
622
+ return this._tokenExpires;
623
+ },
624
+ enumerable: false,
625
+ configurable: true
626
+ });
627
+ Object.defineProperty(UserSession.prototype, "refreshToken", {
628
+ /**
629
+ * The current token to ArcGIS Online or ArcGIS Enterprise.
630
+ */
631
+ get: function () {
632
+ return this._refreshToken;
633
+ },
634
+ enumerable: false,
635
+ configurable: true
636
+ });
637
+ Object.defineProperty(UserSession.prototype, "refreshTokenExpires", {
638
+ /**
639
+ * The expiration time of the current `refreshToken`.
640
+ */
641
+ get: function () {
642
+ return this._refreshTokenExpires;
643
+ },
644
+ enumerable: false,
645
+ configurable: true
646
+ });
647
+ Object.defineProperty(UserSession.prototype, "trustedServers", {
648
+ /**
649
+ * Deprecated, use `federatedServers` instead.
650
+ *
651
+ * @deprecated
652
+ */
653
+ get: function () {
654
+ console.log("DEPRECATED: use federatedServers instead");
655
+ return this.federatedServers;
656
+ },
657
+ enumerable: false,
658
+ configurable: true
659
+ });
660
+ /**
661
+ * Begins a new browser-based OAuth 2.0 sign in. If `options.popup` is `true` the
662
+ * authentication window will open in a new tab/window and the function will return
663
+ * Promise&lt;UserSession&gt;. Otherwise, the user will be redirected to the
664
+ * authorization page in their current tab/window and the function will return `undefined`.
665
+ *
666
+ * @browserOnly
667
+ */
668
+ /* istanbul ignore next */
669
+ UserSession.beginOAuth2 = function (options, win) {
670
+ if (win === void 0) { win = window; }
671
+ if (options.duration) {
672
+ console.log("DEPRECATED: 'duration' is deprecated - use 'expiration' instead");
673
+ }
674
+ var _a = __assign({
675
+ portal: "https://www.arcgis.com/sharing/rest",
676
+ provider: "arcgis",
677
+ expiration: 20160,
678
+ popup: true,
679
+ popupWindowFeatures: "height=400,width=600,menubar=no,location=yes,resizable=yes,scrollbars=yes,status=yes",
680
+ state: options.clientId,
681
+ locale: "",
682
+ }, options), portal = _a.portal, provider = _a.provider, clientId = _a.clientId, expiration = _a.expiration, redirectUri = _a.redirectUri, popup = _a.popup, popupWindowFeatures = _a.popupWindowFeatures, state = _a.state, locale = _a.locale, params = _a.params;
683
+ var url;
684
+ if (provider === "arcgis") {
685
+ url = portal + "/oauth2/authorize?client_id=" + clientId + "&response_type=token&expiration=" + (options.duration || expiration) + "&redirect_uri=" + encodeURIComponent(redirectUri) + "&state=" + state + "&locale=" + locale;
686
+ }
687
+ else {
688
+ url = portal + "/oauth2/social/authorize?client_id=" + clientId + "&socialLoginProviderName=" + provider + "&autoAccountCreateForSocial=true&response_type=token&expiration=" + (options.duration || expiration) + "&redirect_uri=" + encodeURIComponent(redirectUri) + "&state=" + state + "&locale=" + locale;
689
+ }
690
+ // append additional params
691
+ if (params) {
692
+ url = url + "&" + encodeQueryString(params);
693
+ }
694
+ if (!popup) {
695
+ win.location.href = url;
696
+ return undefined;
697
+ }
698
+ var session = defer();
699
+ win["__ESRI_REST_AUTH_HANDLER_" + clientId] = function (errorString, oauthInfoString) {
700
+ if (errorString) {
701
+ var error = JSON.parse(errorString);
702
+ session.reject(new ArcGISAuthError(error.errorMessage, error.error));
703
+ return;
704
+ }
705
+ if (oauthInfoString) {
706
+ var oauthInfo = JSON.parse(oauthInfoString);
707
+ session.resolve(new UserSession({
708
+ clientId: clientId,
709
+ portal: portal,
710
+ ssl: oauthInfo.ssl,
711
+ token: oauthInfo.token,
712
+ tokenExpires: new Date(oauthInfo.expires),
713
+ username: oauthInfo.username,
714
+ }));
715
+ }
716
+ };
717
+ win.open(url, "oauth-window", popupWindowFeatures);
718
+ return session.promise;
719
+ };
720
+ /**
721
+ * Completes a browser-based OAuth 2.0 sign in. If `options.popup` is `true` the user
722
+ * will be returned to the previous window. Otherwise a new `UserSession`
723
+ * will be returned. You must pass the same values for `options.popup` and
724
+ * `options.portal` as you used in `beginOAuth2()`.
725
+ *
726
+ * @browserOnly
727
+ */
728
+ /* istanbul ignore next */
729
+ UserSession.completeOAuth2 = function (options, win) {
730
+ if (win === void 0) { win = window; }
731
+ var _a = __assign({ portal: "https://www.arcgis.com/sharing/rest", popup: true }, options), portal = _a.portal, clientId = _a.clientId, popup = _a.popup;
732
+ function completeSignIn(error, oauthInfo) {
733
+ try {
734
+ var handlerFn = void 0;
735
+ var handlerFnName = "__ESRI_REST_AUTH_HANDLER_" + clientId;
736
+ if (popup) {
737
+ // Guard b/c IE does not support window.opener
738
+ if (win.opener) {
739
+ if (win.opener.parent && win.opener.parent[handlerFnName]) {
740
+ handlerFn = win.opener.parent[handlerFnName];
741
+ }
742
+ else if (win.opener && win.opener[handlerFnName]) {
743
+ // support pop-out oauth from within an iframe
744
+ handlerFn = win.opener[handlerFnName];
745
+ }
746
+ }
747
+ else {
748
+ // IE
749
+ if (win !== win.parent && win.parent && win.parent[handlerFnName]) {
750
+ handlerFn = win.parent[handlerFnName];
751
+ }
752
+ }
753
+ // if we have a handler fn, call it and close the window
754
+ if (handlerFn) {
755
+ handlerFn(error ? JSON.stringify(error) : undefined, JSON.stringify(oauthInfo));
756
+ win.close();
757
+ return undefined;
758
+ }
759
+ }
760
+ }
761
+ catch (e) {
762
+ throw new ArcGISAuthError("Unable to complete authentication. It's possible you specified popup based oAuth2 but no handler from \"beginOAuth2()\" present. This generally happens because the \"popup\" option differs between \"beginOAuth2()\" and \"completeOAuth2()\".");
763
+ }
764
+ if (error) {
765
+ throw new ArcGISAuthError(error.errorMessage, error.error);
766
+ }
767
+ return new UserSession({
768
+ clientId: clientId,
769
+ portal: portal,
770
+ ssl: oauthInfo.ssl,
771
+ token: oauthInfo.token,
772
+ tokenExpires: oauthInfo.expires,
773
+ username: oauthInfo.username,
774
+ });
775
+ }
776
+ var params = decodeQueryString(win.location.hash);
777
+ if (!params.access_token) {
778
+ var error = void 0;
779
+ var errorMessage = "Unknown error";
780
+ if (params.error) {
781
+ error = params.error;
782
+ errorMessage = params.error_description;
783
+ }
784
+ return completeSignIn({ error: error, errorMessage: errorMessage });
785
+ }
786
+ var token = params.access_token;
787
+ var expires = new Date(Date.now() + parseInt(params.expires_in, 10) * 1000 - 60 * 1000);
788
+ var username = params.username;
789
+ var ssl = params.ssl === "true";
790
+ return completeSignIn(undefined, {
791
+ token: token,
792
+ expires: expires,
793
+ ssl: ssl,
794
+ username: username,
795
+ });
796
+ };
797
+ /**
798
+ * Request session information from the parent application
799
+ *
800
+ * When an application is embedded into another application via an IFrame, the embedded app can
801
+ * use `window.postMessage` to request credentials from the host application. This function wraps
802
+ * that behavior.
803
+ *
804
+ * The ArcGIS API for Javascript has this built into the Identity Manager as of the 4.19 release.
805
+ *
806
+ * Note: The parent application will not respond if the embedded app's origin is not:
807
+ * - the same origin as the parent or *.arcgis.com (JSAPI)
808
+ * - in the list of valid child origins (REST-JS)
809
+ *
810
+ *
811
+ * @param parentOrigin origin of the parent frame. Passed into the embedded application as `parentOrigin` query param
812
+ * @browserOnly
813
+ */
814
+ UserSession.fromParent = function (parentOrigin, win) {
815
+ /* istanbul ignore next: must pass in a mockwindow for tests so we can't cover the other branch */
816
+ if (!win && window) {
817
+ win = window;
818
+ }
819
+ // Declare handler outside of promise scope so we can detach it
820
+ var handler;
821
+ // return a promise that will resolve when the handler receives
822
+ // session information from the correct origin
823
+ return new Promise(function (resolve, reject) {
824
+ // create an event handler that just wraps the parentMessageHandler
825
+ handler = function (event) {
826
+ // ensure we only listen to events from the parent
827
+ if (event.source === win.parent && event.data) {
828
+ try {
829
+ return resolve(UserSession.parentMessageHandler(event));
830
+ }
831
+ catch (err) {
832
+ return reject(err);
833
+ }
834
+ }
835
+ };
836
+ // add listener
837
+ win.addEventListener("message", handler, false);
838
+ win.parent.postMessage({ type: "arcgis:auth:requestCredential" }, parentOrigin);
839
+ }).then(function (session) {
840
+ win.removeEventListener("message", handler, false);
841
+ return session;
842
+ });
843
+ };
844
+ /**
845
+ * Begins a new server-based OAuth 2.0 sign in. This will redirect the user to
846
+ * the ArcGIS Online or ArcGIS Enterprise authorization page.
847
+ *
848
+ * @nodeOnly
849
+ */
850
+ UserSession.authorize = function (options, response) {
851
+ if (options.duration) {
852
+ console.log("DEPRECATED: 'duration' is deprecated - use 'expiration' instead");
853
+ }
854
+ var _a = __assign({ portal: "https://arcgis.com/sharing/rest", expiration: 20160 }, options), portal = _a.portal, clientId = _a.clientId, expiration = _a.expiration, redirectUri = _a.redirectUri;
855
+ response.writeHead(301, {
856
+ Location: portal + "/oauth2/authorize?client_id=" + clientId + "&expiration=" + (options.duration || expiration) + "&response_type=code&redirect_uri=" + encodeURIComponent(redirectUri),
857
+ });
858
+ response.end();
859
+ };
860
+ /**
861
+ * Completes the server-based OAuth 2.0 sign in process by exchanging the `authorizationCode`
862
+ * for a `access_token`.
863
+ *
864
+ * @nodeOnly
865
+ */
866
+ UserSession.exchangeAuthorizationCode = function (options, authorizationCode) {
867
+ var _a = __assign({
868
+ portal: "https://www.arcgis.com/sharing/rest",
869
+ refreshTokenTTL: 20160,
870
+ }, options), portal = _a.portal, clientId = _a.clientId, redirectUri = _a.redirectUri, refreshTokenTTL = _a.refreshTokenTTL;
871
+ return fetchToken(portal + "/oauth2/token", {
872
+ params: {
873
+ grant_type: "authorization_code",
874
+ client_id: clientId,
875
+ redirect_uri: redirectUri,
876
+ code: authorizationCode,
877
+ },
878
+ }).then(function (response) {
879
+ return new UserSession({
880
+ clientId: clientId,
881
+ portal: portal,
882
+ ssl: response.ssl,
883
+ redirectUri: redirectUri,
884
+ refreshToken: response.refreshToken,
885
+ refreshTokenTTL: refreshTokenTTL,
886
+ refreshTokenExpires: new Date(Date.now() + (refreshTokenTTL - 1) * 60 * 1000),
887
+ token: response.token,
888
+ tokenExpires: response.expires,
889
+ username: response.username,
890
+ });
891
+ });
892
+ };
893
+ UserSession.deserialize = function (str) {
894
+ var options = JSON.parse(str);
895
+ return new UserSession({
896
+ clientId: options.clientId,
897
+ refreshToken: options.refreshToken,
898
+ refreshTokenExpires: new Date(options.refreshTokenExpires),
899
+ username: options.username,
900
+ password: options.password,
901
+ token: options.token,
902
+ tokenExpires: new Date(options.tokenExpires),
903
+ portal: options.portal,
904
+ ssl: options.ssl,
905
+ tokenDuration: options.tokenDuration,
906
+ redirectUri: options.redirectUri,
907
+ refreshTokenTTL: options.refreshTokenTTL,
908
+ });
909
+ };
910
+ /**
911
+ * Translates authentication from the format used in the [ArcGIS API for JavaScript](https://developers.arcgis.com/javascript/).
912
+ *
913
+ * ```js
914
+ * UserSession.fromCredential({
915
+ * userId: "jsmith",
916
+ * token: "secret"
917
+ * });
918
+ * ```
919
+ *
920
+ * @returns UserSession
921
+ */
922
+ UserSession.fromCredential = function (credential) {
923
+ // At ArcGIS Online 9.1, credentials no longer include the ssl and expires properties
924
+ // Here, we provide default values for them to cover this condition
925
+ var ssl = typeof credential.ssl !== "undefined" ? credential.ssl : true;
926
+ var expires = credential.expires || Date.now() + 7200000; /* 2 hours */
927
+ return new UserSession({
928
+ portal: credential.server.includes("sharing/rest")
929
+ ? credential.server
930
+ : credential.server + "/sharing/rest",
931
+ ssl: ssl,
932
+ token: credential.token,
933
+ username: credential.userId,
934
+ tokenExpires: new Date(expires),
935
+ });
936
+ };
937
+ /**
938
+ * Handle the response from the parent
939
+ * @param event DOM Event
940
+ */
941
+ UserSession.parentMessageHandler = function (event) {
942
+ if (event.data.type === "arcgis:auth:credential") {
943
+ return UserSession.fromCredential(event.data.credential);
944
+ }
945
+ if (event.data.type === "arcgis:auth:error") {
946
+ var err = new Error(event.data.error.message);
947
+ err.name = event.data.error.name;
948
+ throw err;
949
+ }
950
+ else {
951
+ throw new Error("Unknown message type.");
952
+ }
953
+ };
954
+ /**
955
+ * Returns authentication in a format useable in the [ArcGIS API for JavaScript](https://developers.arcgis.com/javascript/).
956
+ *
957
+ * ```js
958
+ * esriId.registerToken(session.toCredential());
959
+ * ```
960
+ *
961
+ * @returns ICredential
962
+ */
963
+ UserSession.prototype.toCredential = function () {
964
+ return {
965
+ expires: this.tokenExpires.getTime(),
966
+ server: this.portal,
967
+ ssl: this.ssl,
968
+ token: this.token,
969
+ userId: this.username,
970
+ };
971
+ };
972
+ /**
973
+ * Returns information about the currently logged in [user](https://developers.arcgis.com/rest/users-groups-and-items/user.htm). Subsequent calls will *not* result in additional web traffic.
974
+ *
975
+ * ```js
976
+ * session.getUser()
977
+ * .then(response => {
978
+ * console.log(response.role); // "org_admin"
979
+ * })
980
+ * ```
981
+ *
982
+ * @param requestOptions - Options for the request. NOTE: `rawResponse` is not supported by this operation.
983
+ * @returns A Promise that will resolve with the data from the response.
984
+ */
985
+ UserSession.prototype.getUser = function (requestOptions) {
986
+ var _this = this;
987
+ if (this._pendingUserRequest) {
988
+ return this._pendingUserRequest;
989
+ }
990
+ else if (this._user) {
991
+ return Promise.resolve(this._user);
992
+ }
993
+ else {
994
+ var url = this.portal + "/community/self";
995
+ var options = __assign(__assign({ httpMethod: "GET", authentication: this }, requestOptions), { rawResponse: false });
996
+ this._pendingUserRequest = request(url, options).then(function (response) {
997
+ _this._user = response;
998
+ _this._pendingUserRequest = null;
999
+ return response;
1000
+ });
1001
+ return this._pendingUserRequest;
1002
+ }
1003
+ };
1004
+ /**
1005
+ * Returns information about the currently logged in user's [portal](https://developers.arcgis.com/rest/users-groups-and-items/portal-self.htm). Subsequent calls will *not* result in additional web traffic.
1006
+ *
1007
+ * ```js
1008
+ * session.getPortal()
1009
+ * .then(response => {
1010
+ * console.log(portal.name); // "City of ..."
1011
+ * })
1012
+ * ```
1013
+ *
1014
+ * @param requestOptions - Options for the request. NOTE: `rawResponse` is not supported by this operation.
1015
+ * @returns A Promise that will resolve with the data from the response.
1016
+ */
1017
+ UserSession.prototype.getPortal = function (requestOptions) {
1018
+ var _this = this;
1019
+ if (this._pendingPortalRequest) {
1020
+ return this._pendingPortalRequest;
1021
+ }
1022
+ else if (this._portalInfo) {
1023
+ return Promise.resolve(this._portalInfo);
1024
+ }
1025
+ else {
1026
+ var url = this.portal + "/portals/self";
1027
+ var options = __assign(__assign({ httpMethod: "GET", authentication: this }, requestOptions), { rawResponse: false });
1028
+ this._pendingPortalRequest = request(url, options).then(function (response) {
1029
+ _this._portalInfo = response;
1030
+ _this._pendingPortalRequest = null;
1031
+ return response;
1032
+ });
1033
+ return this._pendingPortalRequest;
1034
+ }
1035
+ };
1036
+ /**
1037
+ * Returns the username for the currently logged in [user](https://developers.arcgis.com/rest/users-groups-and-items/user.htm). Subsequent calls will *not* result in additional web traffic. This is also used internally when a username is required for some requests but is not present in the options.
1038
+ *
1039
+ * * ```js
1040
+ * session.getUsername()
1041
+ * .then(response => {
1042
+ * console.log(response); // "casey_jones"
1043
+ * })
1044
+ * ```
1045
+ */
1046
+ UserSession.prototype.getUsername = function () {
1047
+ if (this.username) {
1048
+ return Promise.resolve(this.username);
1049
+ }
1050
+ else if (this._user) {
1051
+ return Promise.resolve(this._user.username);
1052
+ }
1053
+ else {
1054
+ return this.getUser().then(function (user) {
1055
+ return user.username;
1056
+ });
1057
+ }
1058
+ };
1059
+ /**
1060
+ * Gets an appropriate token for the given URL. If `portal` is ArcGIS Online and
1061
+ * the request is to an ArcGIS Online domain `token` will be used. If the request
1062
+ * is to the current `portal` the current `token` will also be used. However if
1063
+ * the request is to an unknown server we will validate the server with a request
1064
+ * to our current `portal`.
1065
+ */
1066
+ UserSession.prototype.getToken = function (url, requestOptions) {
1067
+ if (canUseOnlineToken(this.portal, url)) {
1068
+ return this.getFreshToken(requestOptions);
1069
+ }
1070
+ else if (new RegExp(this.portal, "i").test(url)) {
1071
+ return this.getFreshToken(requestOptions);
1072
+ }
1073
+ else {
1074
+ return this.getTokenForServer(url, requestOptions);
1075
+ }
1076
+ };
1077
+ /**
1078
+ * Get application access information for the current user
1079
+ * see `validateAppAccess` function for details
1080
+ *
1081
+ * @param clientId application client id
1082
+ */
1083
+ UserSession.prototype.validateAppAccess = function (clientId) {
1084
+ return this.getToken(this.portal).then(function (token) {
1085
+ return validateAppAccess(token, clientId);
1086
+ });
1087
+ };
1088
+ UserSession.prototype.toJSON = function () {
1089
+ return {
1090
+ clientId: this.clientId,
1091
+ refreshToken: this.refreshToken,
1092
+ refreshTokenExpires: this.refreshTokenExpires,
1093
+ username: this.username,
1094
+ password: this.password,
1095
+ token: this.token,
1096
+ tokenExpires: this.tokenExpires,
1097
+ portal: this.portal,
1098
+ ssl: this.ssl,
1099
+ tokenDuration: this.tokenDuration,
1100
+ redirectUri: this.redirectUri,
1101
+ refreshTokenTTL: this.refreshTokenTTL,
1102
+ };
1103
+ };
1104
+ UserSession.prototype.serialize = function () {
1105
+ return JSON.stringify(this);
1106
+ };
1107
+ /**
1108
+ * For a "Host" app that embeds other platform apps via iframes, after authenticating the user
1109
+ * and creating a UserSession, the app can then enable "post message" style authentication by calling
1110
+ * this method.
1111
+ *
1112
+ * Internally this adds an event listener on window for the `message` event
1113
+ *
1114
+ * @param validChildOrigins Array of origins that are allowed to request authentication from the host app
1115
+ */
1116
+ UserSession.prototype.enablePostMessageAuth = function (validChildOrigins, win) {
1117
+ /* istanbul ignore next: must pass in a mockwindow for tests so we can't cover the other branch */
1118
+ if (!win && window) {
1119
+ win = window;
1120
+ }
1121
+ this._hostHandler = this.createPostMessageHandler(validChildOrigins);
1122
+ win.addEventListener("message", this._hostHandler, false);
1123
+ };
1124
+ /**
1125
+ * For a "Host" app that has embedded other platform apps via iframes, when the host needs
1126
+ * to transition routes, it should call `UserSession.disablePostMessageAuth()` to remove
1127
+ * the event listener and prevent memory leaks
1128
+ */
1129
+ UserSession.prototype.disablePostMessageAuth = function (win) {
1130
+ /* istanbul ignore next: must pass in a mockwindow for tests so we can't cover the other branch */
1131
+ if (!win && window) {
1132
+ win = window;
1133
+ }
1134
+ win.removeEventListener("message", this._hostHandler, false);
1135
+ };
1136
+ /**
1137
+ * Manually refreshes the current `token` and `tokenExpires`.
1138
+ */
1139
+ UserSession.prototype.refreshSession = function (requestOptions) {
1140
+ // make sure subsequent calls to getUser() don't returned cached metadata
1141
+ this._user = null;
1142
+ if (this.username && this.password) {
1143
+ return this.refreshWithUsernameAndPassword(requestOptions);
1144
+ }
1145
+ if (this.clientId && this.refreshToken) {
1146
+ return this.refreshWithRefreshToken();
1147
+ }
1148
+ return Promise.reject(new ArcGISAuthError("Unable to refresh token."));
1149
+ };
1150
+ /**
1151
+ * Determines the root of the ArcGIS Server or Portal for a given URL.
1152
+ *
1153
+ * @param url the URl to determine the root url for.
1154
+ */
1155
+ UserSession.prototype.getServerRootUrl = function (url) {
1156
+ var root = cleanUrl(url).split(/\/rest(\/admin)?\/services(?:\/|#|\?|$)/)[0];
1157
+ var _a = root.match(/(https?:\/\/)(.+)/), protocol = _a[1], domainAndPath = _a[2];
1158
+ var _b = domainAndPath.split("/"), domain = _b[0], path = _b.slice(1);
1159
+ // only the domain is lowercased because in some cases an org id might be
1160
+ // in the path which cannot be lowercased.
1161
+ return "" + protocol + domain.toLowerCase() + "/" + path.join("/");
1162
+ };
1163
+ /**
1164
+ * Returns the proper [`credentials`] option for `fetch` for a given domain.
1165
+ * See [trusted server](https://enterprise.arcgis.com/en/portal/latest/administer/windows/configure-security.htm#ESRI_SECTION1_70CC159B3540440AB325BE5D89DBE94A).
1166
+ * Used internally by underlying request methods to add support for specific security considerations.
1167
+ *
1168
+ * @param url The url of the request
1169
+ * @returns "include" or "same-origin"
1170
+ */
1171
+ UserSession.prototype.getDomainCredentials = function (url) {
1172
+ if (!this.trustedDomains || !this.trustedDomains.length) {
1173
+ return "same-origin";
1174
+ }
1175
+ return this.trustedDomains.some(function (domainWithProtocol) {
1176
+ return url.startsWith(domainWithProtocol);
1177
+ })
1178
+ ? "include"
1179
+ : "same-origin";
1180
+ };
1181
+ /**
1182
+ * Return a function that closes over the validOrigins array and
1183
+ * can be used as an event handler for the `message` event
1184
+ *
1185
+ * @param validOrigins Array of valid origins
1186
+ */
1187
+ UserSession.prototype.createPostMessageHandler = function (validOrigins) {
1188
+ var _this = this;
1189
+ // return a function that closes over the validOrigins and
1190
+ // has access to the credential
1191
+ return function (event) {
1192
+ // Verify that the origin is valid
1193
+ // Note: do not use regex's here. validOrigins is an array so we're checking that the event's origin
1194
+ // is in the array via exact match. More info about avoiding postMessage xss issues here
1195
+ // https://jlajara.gitlab.io/web/2020/07/17/Dom_XSS_PostMessage_2.html#tipsbypasses-in-postmessage-vulnerabilities
1196
+ var isValidOrigin = validOrigins.indexOf(event.origin) > -1;
1197
+ // JSAPI handles this slightly differently - instead of checking a list, it will respond if
1198
+ // event.origin === window.location.origin || event.origin.endsWith('.arcgis.com')
1199
+ // For Hub, and to enable cross domain debugging with port's in urls, we are opting to
1200
+ // use a list of valid origins
1201
+ // Ensure the message type is something we want to handle
1202
+ var isValidType = event.data.type === "arcgis:auth:requestCredential";
1203
+ var isTokenValid = _this.tokenExpires.getTime() > Date.now();
1204
+ if (isValidOrigin && isValidType) {
1205
+ var msg = {};
1206
+ if (isTokenValid) {
1207
+ var credential = _this.toCredential();
1208
+ // arcgis:auth:error with {name: "", message: ""}
1209
+ // the following line allows us to conform to our spec without changing other depended-on functionality
1210
+ // https://github.com/Esri/arcgis-rest-js/blob/master/packages/arcgis-rest-auth/post-message-auth-spec.md#arcgisauthcredential
1211
+ credential.server = credential.server.replace("/sharing/rest", "");
1212
+ msg = { type: "arcgis:auth:credential", credential: credential };
1213
+ }
1214
+ else {
1215
+ // Return an error
1216
+ msg = {
1217
+ type: "arcgis:auth:error",
1218
+ error: {
1219
+ name: "tokenExpiredError",
1220
+ message: "Session token was expired, and not returned to the child application",
1221
+ },
1222
+ };
1223
+ }
1224
+ event.source.postMessage(msg, event.origin);
1225
+ }
1226
+ };
1227
+ };
1228
+ /**
1229
+ * Validates that a given URL is properly federated with our current `portal`.
1230
+ * Attempts to use the internal `federatedServers` cache first.
1231
+ */
1232
+ UserSession.prototype.getTokenForServer = function (url, requestOptions) {
1233
+ var _this = this;
1234
+ // requests to /rest/services/ and /rest/admin/services/ are both valid
1235
+ // Federated servers may have inconsistent casing, so lowerCase it
1236
+ var root = this.getServerRootUrl(url);
1237
+ var existingToken = this.federatedServers[root];
1238
+ if (existingToken &&
1239
+ existingToken.expires &&
1240
+ existingToken.expires.getTime() > Date.now()) {
1241
+ return Promise.resolve(existingToken.token);
1242
+ }
1243
+ if (this._pendingTokenRequests[root]) {
1244
+ return this._pendingTokenRequests[root];
1245
+ }
1246
+ this._pendingTokenRequests[root] = this.fetchAuthorizedDomains().then(function () {
1247
+ return request(root + "/rest/info", {
1248
+ credentials: _this.getDomainCredentials(url),
1249
+ })
1250
+ .then(function (response) {
1251
+ if (response.owningSystemUrl) {
1252
+ /**
1253
+ * if this server is not owned by this portal
1254
+ * bail out with an error since we know we wont
1255
+ * be able to generate a token
1256
+ */
1257
+ if (!isFederated(response.owningSystemUrl, _this.portal)) {
1258
+ throw new ArcGISAuthError(url + " is not federated with " + _this.portal + ".", "NOT_FEDERATED");
1259
+ }
1260
+ else {
1261
+ /**
1262
+ * if the server is federated, use the relevant token endpoint.
1263
+ */
1264
+ return request(response.owningSystemUrl + "/sharing/rest/info", requestOptions);
1265
+ }
1266
+ }
1267
+ else if (response.authInfo &&
1268
+ _this.federatedServers[root] !== undefined) {
1269
+ /**
1270
+ * if its a stand-alone instance of ArcGIS Server that doesn't advertise
1271
+ * federation, but the root server url is recognized, use its built in token endpoint.
1272
+ */
1273
+ return Promise.resolve({
1274
+ authInfo: response.authInfo,
1275
+ });
1276
+ }
1277
+ else {
1278
+ throw new ArcGISAuthError(url + " is not federated with any portal and is not explicitly trusted.", "NOT_FEDERATED");
1279
+ }
1280
+ })
1281
+ .then(function (response) {
1282
+ return response.authInfo.tokenServicesUrl;
1283
+ })
1284
+ .then(function (tokenServicesUrl) {
1285
+ // an expired token cant be used to generate a new token
1286
+ if (_this.token && _this.tokenExpires.getTime() > Date.now()) {
1287
+ return generateToken(tokenServicesUrl, {
1288
+ params: {
1289
+ token: _this.token,
1290
+ serverUrl: url,
1291
+ expiration: _this.tokenDuration,
1292
+ client: "referer",
1293
+ },
1294
+ });
1295
+ // generate an entirely fresh token if necessary
1296
+ }
1297
+ else {
1298
+ return generateToken(tokenServicesUrl, {
1299
+ params: {
1300
+ username: _this.username,
1301
+ password: _this.password,
1302
+ expiration: _this.tokenDuration,
1303
+ client: "referer",
1304
+ },
1305
+ }).then(function (response) {
1306
+ _this._token = response.token;
1307
+ _this._tokenExpires = new Date(response.expires);
1308
+ return response;
1309
+ });
1310
+ }
1311
+ })
1312
+ .then(function (response) {
1313
+ _this.federatedServers[root] = {
1314
+ expires: new Date(response.expires),
1315
+ token: response.token,
1316
+ };
1317
+ delete _this._pendingTokenRequests[root];
1318
+ return response.token;
1319
+ });
1320
+ });
1321
+ return this._pendingTokenRequests[root];
1322
+ };
1323
+ /**
1324
+ * Returns an unexpired token for the current `portal`.
1325
+ */
1326
+ UserSession.prototype.getFreshToken = function (requestOptions) {
1327
+ var _this = this;
1328
+ if (this.token && !this.tokenExpires) {
1329
+ return Promise.resolve(this.token);
1330
+ }
1331
+ if (this.token &&
1332
+ this.tokenExpires &&
1333
+ this.tokenExpires.getTime() > Date.now()) {
1334
+ return Promise.resolve(this.token);
1335
+ }
1336
+ if (!this._pendingTokenRequests[this.portal]) {
1337
+ this._pendingTokenRequests[this.portal] = this.refreshSession(requestOptions).then(function (session) {
1338
+ _this._pendingTokenRequests[_this.portal] = null;
1339
+ return session.token;
1340
+ });
1341
+ }
1342
+ return this._pendingTokenRequests[this.portal];
1343
+ };
1344
+ /**
1345
+ * Refreshes the current `token` and `tokenExpires` with `username` and
1346
+ * `password`.
1347
+ */
1348
+ UserSession.prototype.refreshWithUsernameAndPassword = function (requestOptions) {
1349
+ var _this = this;
1350
+ var options = __assign({ params: {
1351
+ username: this.username,
1352
+ password: this.password,
1353
+ expiration: this.tokenDuration,
1354
+ } }, requestOptions);
1355
+ return generateToken(this.portal + "/generateToken", options).then(function (response) {
1356
+ _this._token = response.token;
1357
+ _this._tokenExpires = new Date(response.expires);
1358
+ return _this;
1359
+ });
1360
+ };
1361
+ /**
1362
+ * Refreshes the current `token` and `tokenExpires` with `refreshToken`.
1363
+ */
1364
+ UserSession.prototype.refreshWithRefreshToken = function (requestOptions) {
1365
+ var _this = this;
1366
+ if (this.refreshToken &&
1367
+ this.refreshTokenExpires &&
1368
+ this.refreshTokenExpires.getTime() < Date.now()) {
1369
+ return this.refreshRefreshToken(requestOptions);
1370
+ }
1371
+ var options = __assign({ params: {
1372
+ client_id: this.clientId,
1373
+ refresh_token: this.refreshToken,
1374
+ grant_type: "refresh_token",
1375
+ } }, requestOptions);
1376
+ return fetchToken(this.portal + "/oauth2/token", options).then(function (response) {
1377
+ _this._token = response.token;
1378
+ _this._tokenExpires = response.expires;
1379
+ return _this;
1380
+ });
1381
+ };
1382
+ /**
1383
+ * Exchanges an unexpired `refreshToken` for a new one, also updates `token` and
1384
+ * `tokenExpires`.
1385
+ */
1386
+ UserSession.prototype.refreshRefreshToken = function (requestOptions) {
1387
+ var _this = this;
1388
+ var options = __assign({ params: {
1389
+ client_id: this.clientId,
1390
+ refresh_token: this.refreshToken,
1391
+ redirect_uri: this.redirectUri,
1392
+ grant_type: "exchange_refresh_token",
1393
+ } }, requestOptions);
1394
+ return fetchToken(this.portal + "/oauth2/token", options).then(function (response) {
1395
+ _this._token = response.token;
1396
+ _this._tokenExpires = response.expires;
1397
+ _this._refreshToken = response.refreshToken;
1398
+ _this._refreshTokenExpires = new Date(Date.now() + (_this.refreshTokenTTL - 1) * 60 * 1000);
1399
+ return _this;
1400
+ });
1401
+ };
1402
+ /**
1403
+ * ensures that the authorizedCrossOriginDomains are obtained from the portal and cached
1404
+ * so we can check them later.
1405
+ *
1406
+ * @returns this
1407
+ */
1408
+ UserSession.prototype.fetchAuthorizedDomains = function () {
1409
+ var _this = this;
1410
+ // if this token is for a specific server or we don't have a portal
1411
+ // don't get the portal info because we cant get the authorizedCrossOriginDomains
1412
+ if (this.server || !this.portal) {
1413
+ return Promise.resolve(this);
1414
+ }
1415
+ return this.getPortal().then(function (portalInfo) {
1416
+ /**
1417
+ * Specific domains can be configured as secure.esri.com or https://secure.esri.com this
1418
+ * normalizes to https://secure.esri.com so we can use startsWith later.
1419
+ */
1420
+ if (portalInfo.authorizedCrossOriginDomains &&
1421
+ portalInfo.authorizedCrossOriginDomains.length) {
1422
+ _this.trustedDomains = portalInfo.authorizedCrossOriginDomains
1423
+ .filter(function (d) { return !d.startsWith("http://"); })
1424
+ .map(function (d) {
1425
+ if (d.startsWith("https://")) {
1426
+ return d;
1427
+ }
1428
+ else {
1429
+ return "https://" + d;
1430
+ }
1431
+ });
1432
+ }
1433
+ return _this;
1434
+ });
1435
+ };
1436
+ return UserSession;
1437
+ }());
1438
+
1439
+ const solutionConfigurationCss = ".configuration-container{position:relative;height:100%;width:100%}.configuration{position:absolute;top:0px;right:0px;bottom:0px;left:0px;display:flex;padding:0.5rem;border:1px #808080 solid}.config-tabs{width:100%}.config-tab{width:100%}.config-solution{position:absolute;top:3.5rem;right:-1px;bottom:-1px;left:-1px;display:flex;padding:0.5rem}.config-inventory{display:inline;max-width:-moz-min-content;max-width:min-content;flex-grow:0;overflow-y:auto}.config-inventory-hide{display:none;max-width:-moz-min-content;max-width:min-content;flex-grow:0;overflow-y:auto}.config-item{position:relative;display:inline;flex-grow:1;overflow-y:auto;-webkit-margin-start:0.5rem;margin-inline-start:0.5rem}solution-contents{position:relative;height:100%}solution-item{position:relative;height:100%}solution-spatial-ref{position:relative;height:100%;width:100%;overflow-y:auto}";
1440
+
1441
+ const SolutionConfiguration = class {
1442
+ async serializedAuthenticationWatchHandler() {
1443
+ this.authentication = this.serializedAuthentication ? UserSession.deserialize(this.serializedAuthentication) : new UserSession({});
1444
+ }
1445
+ async valueWatchHandler() {
1446
+ await this._loadSolution(this.solutionItemId);
1447
+ }
1448
+ //--------------------------------------------------------------------------
1449
+ //
1450
+ // Lifecycle
1451
+ //
1452
+ //--------------------------------------------------------------------------
1453
+ constructor(hostRef) {
1454
+ registerInstance(this, hostRef);
1455
+ this._solutionStoreHasChanges = false;
1456
+ this._solutionEditorHasChanges = false;
1457
+ this._solutionEditorHasErrors = false;
1458
+ this._canSave = false;
1459
+ this.authentication = new UserSession({});
1460
+ this.serializedAuthentication = "";
1461
+ this.solutionItemId = "";
1462
+ this.showLoading = false;
1463
+ this._currentEditItemId = "";
1464
+ this._organizationVariables = "";
1465
+ this._solutionContentsComponent = undefined;
1466
+ this._solutionIsLoaded = false;
1467
+ this._solutionVariables = "";
1468
+ this._templateHierarchy = [];
1469
+ this._translations = undefined;
1470
+ this._treeOpen = true;
1471
+ if (this.serializedAuthentication) {
1472
+ this.authentication = UserSession.deserialize(this.serializedAuthentication);
1473
+ }
1474
+ void this._loadSolution(this.solutionItemId);
1475
+ window.addEventListener("solutionStoreHasChanges", (evt) => {
1476
+ this._updateSaveability(this._solutionStoreHasChanges = evt.detail, this._solutionEditorHasChanges, this._solutionEditorHasErrors);
1477
+ });
1478
+ window.addEventListener("solutionEditorHasChanges", (evt) => {
1479
+ this._updateSaveability(this._solutionStoreHasChanges, this._solutionEditorHasChanges = evt.detail, this._solutionEditorHasErrors);
1480
+ });
1481
+ window.addEventListener("solutionEditorHasErrors", (evt) => {
1482
+ this._updateSaveability(this._solutionStoreHasChanges, this._solutionEditorHasChanges, this._solutionEditorHasErrors = evt.detail);
1483
+ });
1484
+ }
1485
+ /**
1486
+ * StencilJS: Called once just after the component is first connected to the DOM.
1487
+ *
1488
+ * @returns Promise when complete
1489
+ */
1490
+ async componentWillLoad() {
1491
+ return this._getTranslations();
1492
+ }
1493
+ /**
1494
+ * Renders the component.
1495
+ */
1496
+ render() {
1497
+ const wkid = getProp(state.getStoreInfo("spatialReferenceInfo"), "spatialReference");
1498
+ const hasServices = state.getStoreInfo("featureServices").length > 0;
1499
+ const solutionData = state.getStoreInfo("solutionData");
1500
+ this._solutionVariables = JSON.stringify(getSolutionVariables(solutionData.templates, this._translations));
1501
+ this._organizationVariables = JSON.stringify(getOrganizationVariables(this._translations));
1502
+ return (h(Host, null, !this._solutionIsLoaded
1503
+ ? h("calcite-loader", { active: true, label: '' })
1504
+ : null, h("div", { class: "configuration-container" }, h("div", { class: "configuration" }, h("calcite-tabs", { class: "config-tabs" }, h("calcite-tab-nav", { slot: "tab-nav" }, h("calcite-tab-title", null, this._translations.definitionTab), hasServices ?
1505
+ h("calcite-tab-title", null, this._translations.spatialReferenceTab) :
1506
+ null), h("calcite-tab", { class: "config-tab", selected: true }, h("div", { class: "config-solution" }, h("div", { class: this._treeOpen ? "config-inventory" : "config-inventory-hide" }, h("solution-contents", { id: "configInventory", key: `${this.solutionItemId}-contents`, ref: (el) => (this._solutionContentsComponent = el) })), h("calcite-button", { appearance: "transparent", class: "collapse-btn", "icon-start": this._treeOpen ? "chevrons-left" : "chevrons-right", id: "collapse-vars", onClick: () => this._toggleTree(), scale: "s", title: this._treeOpen ? this._translations.collapse : this._translations.expand }), h("div", { class: "config-item" }, h("solution-item", { authentication: this.authentication, "item-id": this._currentEditItemId, key: `${this.solutionItemId}-item`, "organization-variables": this._organizationVariables, "solution-item-id": this.solutionItemId, "solution-variables": this._solutionVariables })))), hasServices
1507
+ ? h("calcite-tab", { class: "config-tab" }, h("div", { class: "config-solution" }, h("solution-spatial-ref", { defaultWkid: wkid, id: "configure-solution-spatial-ref", key: `${this.solutionItemId}-spatial-ref`, locked: !wkid, services: state.getStoreInfo("featureServices").map(fs => fs.name) })))
1508
+ : null)))));
1509
+ }
1510
+ //--------------------------------------------------------------------------
1511
+ //
1512
+ // Event Listeners
1513
+ //
1514
+ //--------------------------------------------------------------------------
1515
+ _solutionItemSelected(event) {
1516
+ this._currentEditItemId = event.detail;
1517
+ }
1518
+ //--------------------------------------------------------------------------
1519
+ //
1520
+ // Events
1521
+ //
1522
+ //--------------------------------------------------------------------------
1523
+ //--------------------------------------------------------------------------
1524
+ //
1525
+ // Public Methods (async)
1526
+ //
1527
+ //--------------------------------------------------------------------------
1528
+ /*
1529
+ @Method()
1530
+ async getEditModels(): Promise<ISolutionItems> {
1531
+ return Promise.resolve(state.items);
1532
+ }
1533
+ */
1534
+ async getSpatialReferenceInfo() {
1535
+ return Promise.resolve(state.getStoreInfo("spatialReferenceInfo"));
1536
+ }
1537
+ /*
1538
+ @Method()
1539
+ async getSourceTemplates(): Promise<any> {
1540
+ return Promise.resolve(this._templates);
1541
+ }
1542
+ */
1543
+ async saveSolution() {
1544
+ this._solutionIsLoaded = false;
1545
+ await state.saveSolution();
1546
+ this._solutionIsLoaded = true;
1547
+ this.solutionItemId = null;
1548
+ }
1549
+ async unloadSolution() {
1550
+ this.solutionItemId = null;
1551
+ }
1552
+ //--------------------------------------------------------------------------
1553
+ //
1554
+ // Private Methods
1555
+ //
1556
+ //--------------------------------------------------------------------------
1557
+ /**
1558
+ * Update the store with the initial values
1559
+ *
1560
+ * @param templates the solution items templates
1561
+ * @param isReset (defaults to false) indicates if we are resetting the controls after save
1562
+ */
1563
+ /*
1564
+ protected _initState(
1565
+ templates: any[],
1566
+ isReset = false
1567
+ ): Promise<any> {
1568
+ return new Promise((resolve, reject) => {
1569
+ if (isReset) {
1570
+ // clear models and state so we can refresh after save
1571
+ this.modelsSet = false;
1572
+ state.reset();
1573
+ }
1574
+ getModels(templates, this.authentication, this.solutionItemId).then(models => {
1575
+ state.models = models;
1576
+
1577
+ state.featureServices = getFeatureServices(templates);
1578
+ state.getStoreInfo("spatialReferenceInfo") = getSpatialReferenceInfo(state.featureServices, this._sourceItemData);
1579
+
1580
+ if (isReset) {
1581
+ // reset for undo/redo stack and diff editor tracking
1582
+ const jsonEditors = Array.from(this.el.getElementsByTagName("json-editor"));
1583
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
1584
+ jsonEditors.forEach(e => void e.reset());
1585
+ }
1586
+
1587
+ this.modelsSet = true;
1588
+ resolve(true);
1589
+ }, () => reject);
1590
+ });
1591
+ }
1592
+ */
1593
+ /**
1594
+ * Set Props with the initial values
1595
+ *
1596
+ * @protected
1597
+ */
1598
+ _initProps() {
1599
+ const solutionData = state.getStoreInfo("solutionData");
1600
+ this._templateHierarchy = [...getInventoryItems(solutionData.templates)];
1601
+ if (this._solutionContentsComponent) {
1602
+ this._solutionContentsComponent.templateHierarchy = this._templateHierarchy;
1603
+ }
1604
+ let firstItem;
1605
+ if (this._templateHierarchy.length > 0) {
1606
+ // Start with the first item in the contents
1607
+ firstItem = state.getItemInfo(this._templateHierarchy[0].id);
1608
+ }
1609
+ this._currentEditItemId = firstItem ? firstItem.itemId : "";
1610
+ }
1611
+ /**
1612
+ * Loads a solution.
1613
+ *
1614
+ * @param solutionItemId AGO id of solution to load
1615
+ *
1616
+ * @returns Resolved promise when task is done
1617
+ *
1618
+ * @protected
1619
+ */
1620
+ async _loadSolution(solutionItemId) {
1621
+ if (solutionItemId) {
1622
+ this._solutionIsLoaded = false;
1623
+ await state.loadSolution(solutionItemId, this.authentication);
1624
+ this._initProps();
1625
+ this._solutionIsLoaded = true;
1626
+ }
1627
+ else {
1628
+ this._reset();
1629
+ }
1630
+ return Promise.resolve();
1631
+ }
1632
+ /**
1633
+ * Resets internal variables.
1634
+ *
1635
+ * @protected
1636
+ */
1637
+ _reset() {
1638
+ this._currentEditItemId = "";
1639
+ this._organizationVariables = "";
1640
+ this._solutionVariables = "";
1641
+ this._templateHierarchy = [];
1642
+ }
1643
+ /**
1644
+ * Toggle _treeOpen prop to show/hide content tree.
1645
+ *
1646
+ * @protected
1647
+ */
1648
+ _toggleTree() {
1649
+ this._treeOpen = !this._treeOpen;
1650
+ }
1651
+ /**
1652
+ * Dispatches an event indicating if the configuration is saveable or not. It's not saveable if there are no
1653
+ * changes or if there's an error in the JSON editor.
1654
+ *
1655
+ * @param solutionStoreHasChanges Are there changes in the configuration editor's internal store?
1656
+ * @param solutionEditorHasChanges Are there changes in the configuration editor's JSON editor?
1657
+ * @param solutionEditorHasErrors Are there errors in the configuration editor's JSON editor?
1658
+ *
1659
+ * @protected
1660
+ */
1661
+ _updateSaveability(solutionStoreHasChanges, solutionEditorHasChanges, solutionEditorHasErrors) {
1662
+ const updateSaveability = (solutionStoreHasChanges || solutionEditorHasChanges) && !solutionEditorHasErrors;
1663
+ if (this._canSave !== updateSaveability) {
1664
+ window.dispatchEvent(new CustomEvent("solutionCanSave", {
1665
+ detail: updateSaveability,
1666
+ bubbles: true,
1667
+ cancelable: false,
1668
+ composed: true
1669
+ }));
1670
+ }
1671
+ this._canSave = updateSaveability;
1672
+ }
1673
+ /**
1674
+ * Save all edits from the current configuration
1675
+ *
1676
+ * @returns a response that will indicate success or failure and any associated messages
1677
+ */
1678
+ /*
1679
+ protected async _save() {
1680
+ const templateUpdates = await this._updateTemplates();
1681
+ const data = this._setSrInfo(templateUpdates.templates);
1682
+ return templateUpdates.errors.length === 0 ? save(
1683
+ this.solutionItemId,
1684
+ data,
1685
+ state.models,
1686
+ this.authentication,
1687
+ this._translations
1688
+ ).then(saveResult => {
1689
+ // need to trigger re-render...and re-fetch
1690
+ this._fetchData = true;
1691
+ this.modelsSet = false;
1692
+ return Promise.resolve(saveResult)
1693
+ }).catch(e => Promise.reject(e)) : Promise.reject({
1694
+ success: false,
1695
+ message: `The following templates have errors: ${templateUpdates.errors.join(", ")}`
1696
+ } as IResponse);
1697
+ }
1698
+ */
1699
+ /**
1700
+ * Update the solutions templates based on the stored changes
1701
+ *
1702
+ * @returns an object that contains the updated templates as well as any errors that were found
1703
+ */
1704
+ /*
1705
+ protected async _updateTemplates(): Promise<IUpdateTemplateResponse> {
1706
+ const errors = [];
1707
+ const models = await this.getEditModels();
1708
+ let templates = this._updateGroupDependencies(models, this._templates);
1709
+ Object.keys(models).forEach(k => {
1710
+ const m = models[k];
1711
+ templates = templates.map(t => {
1712
+ if (t.itemId === m.itemId) {
1713
+ this._setItem(t, m);
1714
+ const hasDataError = this._setData(t, m);
1715
+ const hasPropError = this._setProps(t, m);
1716
+ if (hasDataError || hasPropError) {
1717
+ errors.push(m.itemId);
1718
+ }
1719
+ }
1720
+ return t;
1721
+ });
1722
+ });
1723
+ errors.concat(window.monaco.editor.getModelMarkers({}));
1724
+ return Promise.resolve({
1725
+ templates,
1726
+ errors
1727
+ });
1728
+ }
1729
+ */
1730
+ /**
1731
+ * Review all models and store itemIds that should be added or removed from group dependencies
1732
+ *
1733
+ * @param models the corresponding models for the current templates
1734
+ *
1735
+ * @returns group info (an object with keys of groupIds and
1736
+ * arrays of itemIds that should be added or removed from group dependencies)
1737
+ */
1738
+ /*
1739
+ protected _getGroupInfo(
1740
+ models: any
1741
+ ): any {
1742
+ const groupInfo = {}
1743
+ Object.keys(models).forEach(k => {
1744
+ const m = models[k];
1745
+ if (m.shareInfo) {
1746
+ const groupId = m.shareInfo.groupId;
1747
+ const type = m.shareInfo.shared ? "share" : "unshare";
1748
+ if (groupInfo[groupId]) {
1749
+ groupInfo[groupId][type].push(m.itemId);
1750
+ } else {
1751
+ groupInfo[groupId] = {};
1752
+ groupInfo[groupId][type] = [m.itemId];
1753
+ if (m.shareInfo.shared) {
1754
+ groupInfo[groupId]["unshare"] = [];
1755
+ } else {
1756
+ groupInfo[groupId]["share"] = [];
1757
+ }
1758
+ }
1759
+ }
1760
+ });
1761
+ return groupInfo;
1762
+ }
1763
+ */
1764
+ /**
1765
+ * Updates group dependency arrays by adding or removing itemIds
1766
+ *
1767
+ * @param templates the current templates to update
1768
+ * @param models the corresponding models for the current templates
1769
+ *
1770
+ * @returns updated templates array
1771
+ */
1772
+ /*
1773
+ protected _updateGroupDependencies(
1774
+ models: any,
1775
+ templates: any[]
1776
+ ): any[] {
1777
+ const groupInfo = this._getGroupInfo(models);
1778
+ Object.keys(groupInfo).forEach(k => {
1779
+ templates.some(t => {
1780
+ if (t.itemId === k) {
1781
+ // add share items as deps
1782
+ groupInfo[k].share.forEach(s => {
1783
+ if (t.dependencies.indexOf(s) < 0) {
1784
+ t.dependencies.push(s);
1785
+ }
1786
+ });
1787
+
1788
+ // remove unshare items from deps
1789
+ groupInfo[k].unshare.forEach(s => {
1790
+ const index = t.dependencies.indexOf(s);
1791
+ if (index > -1) {
1792
+ t.dependencies.splice(index, 1);
1793
+ }
1794
+ });
1795
+ return true;
1796
+ } else {
1797
+ return false;
1798
+ }
1799
+ })
1800
+ })
1801
+ return templates;
1802
+ }
1803
+ */
1804
+ /**
1805
+ * Add group IDs to items that should be shared
1806
+ * This function will update the provided template when shareInfo is available
1807
+ *
1808
+ * @param template the current template to update
1809
+ * @param shareInfo the corresponding shareInfo from the model for the current template
1810
+ *
1811
+ */
1812
+ /*
1813
+ protected _updateItemGroups(
1814
+ template: any,
1815
+ shareInfo: any
1816
+ ): void {
1817
+ if (shareInfo) {
1818
+ const groupIndex = template.groups.indexOf(shareInfo.groupId);
1819
+ if (groupIndex < 0 && shareInfo.shared) {
1820
+ template.groups.push(shareInfo.groupId);
1821
+ }
1822
+ if (groupIndex > -1 && !shareInfo.shared) {
1823
+ template.groups.splice(groupIndex, 1);
1824
+ }
1825
+ }
1826
+ }
1827
+ */
1828
+ /**
1829
+ * Set a templates data property with changes from the models
1830
+ *
1831
+ * @param template the current template to update
1832
+ * @param model the corresponding model for the current template (stores any user changes)
1833
+ *
1834
+ * @returns a boolean that indicates if any errors were detected
1835
+ */
1836
+ /*
1837
+ protected _setData(
1838
+ template: any,
1839
+ model: any
1840
+ ): boolean {
1841
+ return this._setTemplateProp(
1842
+ template,
1843
+ model.dataOriginalValue,
1844
+ model.dataCurrentValue,
1845
+ "data"
1846
+ );
1847
+ }
1848
+ */
1849
+ /**
1850
+ * Set a templates properties property with changes from the models
1851
+ *
1852
+ * @param template the current template to update
1853
+ * @param model the corresponding model for the current template (stores any user changes)
1854
+ *
1855
+ * @returns a boolean that indicates if any errors were detected
1856
+ */
1857
+ /*
1858
+ protected _setProps(
1859
+ template: any,
1860
+ model: any
1861
+ ): boolean {
1862
+ return this._setTemplateProp(
1863
+ template,
1864
+ model.propsOriginalValue,
1865
+ model.propsCurrentValue,
1866
+ "properties"
1867
+ );
1868
+ }
1869
+ */
1870
+ /**
1871
+ * Generic function used to set properties or data property on a given template
1872
+ *
1873
+ * @param template the current template to update
1874
+ * @param originValue the original value from the solution template
1875
+ * @param modelValue the current value from the model (will contain any edits that have been made)
1876
+ * @param path the path to the property we should update if any changes are found
1877
+ *
1878
+ * @returns a boolean that indicates if any errors were detected
1879
+ */
1880
+ /*
1881
+ protected _setTemplateProp(
1882
+ template: any,
1883
+ originValue: any,
1884
+ modelValue: any,
1885
+ path: string
1886
+ ): boolean {
1887
+ let hasError = false;
1888
+ try {
1889
+ const _originValue = JSON.parse(originValue);
1890
+ const _modelValue = JSON.parse(modelValue);
1891
+
1892
+ if (_originValue && _modelValue && (JSON.stringify(_originValue) !== JSON.stringify(_modelValue))) {
1893
+ setProp(template, path, _modelValue);
1894
+ }
1895
+ } catch (e) {
1896
+ console.error(e);
1897
+ hasError = true;
1898
+ }
1899
+ return hasError;
1900
+ }
1901
+ */
1902
+ /**
1903
+ * Set a templates item property with changes from the models
1904
+ *
1905
+ * @param template the current template to update
1906
+ * @param model the corresponding model for the current template (stores any user changes)
1907
+ *
1908
+ * This function will update the template argument when edits are found
1909
+ */
1910
+ /*
1911
+ protected _setItem(
1912
+ template: any,
1913
+ model: any
1914
+ ): void {
1915
+ this._updateItemGroups(template, model.shareInfo);
1916
+ if (model.updateItemValues && Object.keys(model.updateItemValues).length > 0) {
1917
+ Object.keys(model.updateItemValues).forEach(k => {
1918
+ template.item[k] = model.updateItemValues[k];
1919
+ });
1920
+ }
1921
+ }
1922
+ */
1923
+ /**
1924
+ * Set spatial reference info in the solutions data
1925
+ *
1926
+ * @param templates a list of item templates from the solution
1927
+ *
1928
+ * @returns a cloned copy of the solutions data that has been updated with spatial reference info
1929
+ *
1930
+ */
1931
+ /*
1932
+ protected _setSrInfo(
1933
+ templates: any[]
1934
+ ): any {
1935
+ const srInfo: any = state.getStoreInfo("spatialReferenceInfo");
1936
+
1937
+ const serviceEnabled = typeof srInfo?.services === "undefined" ?
1938
+ false : Object.keys(srInfo.services).some(k => srInfo.services[k]);
1939
+
1940
+ const data = cloneObject(this._sourceItemData);
1941
+ data.templates = templates;
1942
+ if (srInfo && srInfo.enabled && serviceEnabled) {
1943
+ const wkid = srInfo.spatialReference.wkid.toString();
1944
+
1945
+ const wkidParam = {
1946
+ "label": "Spatial Reference",
1947
+ "default": wkid,
1948
+ "valueType": "spatialReference",
1949
+ "attributes": {
1950
+ "required": "true"
1951
+ }
1952
+ };
1953
+
1954
+ const params = getProp(data, "params");
1955
+ const hasWkid = params && params.wkid;
1956
+ setCreateProp(
1957
+ data,
1958
+ hasWkid ? "params.wkid.default" : "params.wkid",
1959
+ hasWkid ? wkid : params ? wkidParam : wkid
1960
+ );
1961
+ } else if (!srInfo.enabled) {
1962
+ if (getProp(data, "params.wkid")) {
1963
+ delete (data.params.wkid);
1964
+ }
1965
+ }
1966
+ return data;
1967
+ }
1968
+ */
1969
+ /**
1970
+ * Fetches the component's translations
1971
+ *
1972
+ * @protected
1973
+ */
1974
+ async _getTranslations() {
1975
+ const translations = await getLocaleComponentStrings(this.el);
1976
+ this._translations = translations[0];
1977
+ }
1978
+ get el() { return getElement(this); }
1979
+ static get watchers() { return {
1980
+ "serializedAuthentication": ["serializedAuthenticationWatchHandler"],
1981
+ "solutionItemId": ["valueWatchHandler"]
1982
+ }; }
1983
+ };
1984
+ SolutionConfiguration.style = solutionConfigurationCss;
1985
+
1986
+ export { SolutionConfiguration as solution_configuration };