@esri/solutions-components 0.2.6 → 0.2.7

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