@esri/solutions-components 0.6.16 → 0.6.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/README.md +1 -1
  2. package/dist/assets/t9n/map-tools/resources.json +2 -1
  3. package/dist/assets/t9n/map-tools/resources_en.json +2 -1
  4. package/dist/assets/t9n/solution-spatial-ref/resources.json +0 -1
  5. package/dist/assets/t9n/solution-spatial-ref/resources_en.json +0 -1
  6. package/dist/assets/t9n/solution-spatial-ref/resources_fr.json +6 -0
  7. package/dist/assets/t9n/solution-spatial-ref/resources_he.json +6 -0
  8. package/dist/assets/t9n/spatial-ref/resources.json +3 -0
  9. package/dist/assets/t9n/spatial-ref/resources_en.json +3 -0
  10. package/dist/assets/t9n/spatial-ref/resources_fr.json +3 -0
  11. package/dist/assets/t9n/spatial-ref/resources_he.json +3 -0
  12. package/dist/cjs/{basemap-gallery_6.cjs.entry.js → basemap-gallery_7.cjs.entry.js} +124 -3
  13. package/dist/cjs/{calcite-tree_3.cjs.entry.js → calcite-checkbox_3.cjs.entry.js} +123 -319
  14. package/dist/cjs/calcite-combobox_6.cjs.entry.js +1 -1
  15. package/dist/cjs/calcite-shell-panel_14.cjs.entry.js +4 -3
  16. package/dist/cjs/card-manager_3.cjs.entry.js +10 -7
  17. package/dist/{collection/components/basemap-gallery/test/basemap-gallery.e2e.js → cjs/common-13719149.js} +17 -9
  18. package/dist/cjs/crowdsource-manager.cjs.entry.js +12 -7
  19. package/dist/cjs/{downloadUtils-34a515ad.js → downloadUtils-121fd7ff.js} +2 -2
  20. package/dist/cjs/edit-card_2.cjs.entry.js +4 -3
  21. package/dist/cjs/{index.es-0ba11065.js → index.es-5c0c137a.js} +2 -2
  22. package/dist/cjs/loader.cjs.js +1 -1
  23. package/dist/cjs/map-select-tools_3.cjs.entry.js +2 -2
  24. package/dist/cjs/{mapViewUtils-a2884698.js → mapViewUtils-786a219b.js} +32 -19
  25. package/dist/cjs/public-notification.cjs.entry.js +2 -2
  26. package/dist/cjs/solution-configuration.cjs.entry.js +2 -1
  27. package/dist/cjs/solution-contents_3.cjs.entry.js +21 -21256
  28. package/dist/cjs/solution-item-icon.cjs.entry.js +327 -0
  29. package/dist/cjs/{solution-store-c443e657.js → solution-resource-f9e3b289.js} +2 -1698
  30. package/dist/cjs/solution-store-2414dd8a.js +1707 -0
  31. package/dist/cjs/solutions-components.cjs.js +1 -1
  32. package/dist/cjs/spatial-ref.cjs.entry.js +21293 -0
  33. package/dist/collection/collection-manifest.json +2 -0
  34. package/dist/collection/components/card-manager/card-manager.js +1 -1
  35. package/dist/collection/components/crowdsource-manager/crowdsource-manager.css +17 -2
  36. package/dist/collection/components/crowdsource-manager/crowdsource-manager.js +47 -6
  37. package/dist/collection/components/edit-card/edit-card.css +0 -8
  38. package/dist/collection/components/floor-filter/floor-filter.css +19 -0
  39. package/dist/collection/components/floor-filter/floor-filter.js +163 -0
  40. package/dist/collection/components/info-card/info-card.js +3 -2
  41. package/dist/collection/components/layer-table/layer-table.css +8 -0
  42. package/dist/collection/components/layer-table/layer-table.js +18 -2
  43. package/dist/collection/components/map-card/map-card.js +19 -1
  44. package/dist/collection/components/map-picker/map-picker.css +0 -4
  45. package/dist/collection/components/map-picker/map-picker.js +1 -1
  46. package/dist/collection/components/map-tools/map-tools.js +54 -1
  47. package/dist/collection/components/solution-spatial-ref/solution-spatial-ref.css +1 -7
  48. package/dist/collection/components/solution-spatial-ref/solution-spatial-ref.js +37 -291
  49. package/dist/collection/components/solution-spatial-ref/test/solution-spatial-ref.e2e.js +24 -12
  50. package/dist/collection/components/solution-spatial-ref/test/solution-spatial-ref.spec.js +32 -128
  51. package/dist/collection/components/spatial-ref/spatial-ref.css +20 -0
  52. package/dist/collection/components/spatial-ref/spatial-ref.js +445 -0
  53. package/dist/collection/components/spatial-ref/test/spatial-ref.e2e.js +71 -0
  54. package/dist/collection/components/spatial-ref/test/spatial-ref.spec.js +158 -0
  55. package/dist/collection/demos/crowdsource-manager.html +4 -0
  56. package/dist/collection/demos/solution-spatial-ref.html +9 -16
  57. package/dist/collection/demos/spatial-ref.html +53 -0
  58. package/dist/collection/utils/mapViewUtils.js +32 -19
  59. package/dist/collection/utils/mapViewUtils.ts +43 -20
  60. package/dist/collection/utils/{templates.e2e.js → test/templates.e2e.js} +2 -2
  61. package/dist/collection/utils/{templates.e2e.ts → test/templates.e2e.ts} +2 -2
  62. package/dist/components/card-manager2.js +1 -1
  63. package/dist/components/crowdsource-manager.js +86 -73
  64. package/dist/components/edit-card2.js +1 -1
  65. package/dist/components/floor-filter.d.ts +11 -0
  66. package/dist/components/floor-filter.js +11 -0
  67. package/dist/components/floor-filter2.js +115 -0
  68. package/dist/components/info-card2.js +3 -2
  69. package/dist/components/layer-table2.js +5 -3
  70. package/dist/components/map-card2.js +45 -37
  71. package/dist/components/map-picker2.js +2 -2
  72. package/dist/components/map-tools2.js +52 -11
  73. package/dist/components/mapViewUtils.js +32 -19
  74. package/dist/components/solution-configuration.js +79 -72
  75. package/dist/components/solution-resource-item2.js +2 -1
  76. package/dist/components/solution-resource.js +1836 -0
  77. package/dist/components/solution-spatial-ref2.js +41 -21277
  78. package/dist/components/solution-store.js +2 -1830
  79. package/dist/components/spatial-ref.d.ts +11 -0
  80. package/dist/components/spatial-ref.js +11 -0
  81. package/dist/components/spatial-ref2.js +21374 -0
  82. package/dist/esm/{basemap-gallery_6.entry.js → basemap-gallery_7.entry.js} +124 -4
  83. package/dist/esm/{calcite-tree_3.entry.js → calcite-checkbox_3.entry.js} +125 -321
  84. package/dist/esm/calcite-combobox_6.entry.js +1 -1
  85. package/dist/esm/calcite-shell-panel_14.entry.js +2 -1
  86. package/dist/esm/card-manager_3.entry.js +10 -7
  87. package/dist/{collection/components/layer-table/test/layer-table.e2e.js → esm/common-e4a8e353.js} +15 -9
  88. package/dist/esm/crowdsource-manager.entry.js +12 -7
  89. package/dist/esm/{downloadUtils-ac67a786.js → downloadUtils-287994b1.js} +2 -2
  90. package/dist/esm/edit-card_2.entry.js +4 -3
  91. package/dist/esm/{index.es-f553598f.js → index.es-a3f8409f.js} +2 -2
  92. package/dist/esm/loader.js +1 -1
  93. package/dist/esm/map-select-tools_3.entry.js +2 -2
  94. package/dist/esm/{mapViewUtils-8141d8c1.js → mapViewUtils-8bfabd80.js} +32 -19
  95. package/dist/esm/public-notification.entry.js +2 -2
  96. package/dist/esm/solution-configuration.entry.js +2 -1
  97. package/dist/esm/solution-contents_3.entry.js +20 -21255
  98. package/dist/esm/solution-item-icon.entry.js +323 -0
  99. package/dist/esm/{solution-store-b29d50f7.js → solution-resource-be35d35b.js} +1 -1697
  100. package/dist/esm/solution-store-e734626a.js +1704 -0
  101. package/dist/esm/solutions-components.js +1 -1
  102. package/dist/esm/spatial-ref.entry.js +21289 -0
  103. package/dist/solutions-components/demos/crowdsource-manager.html +4 -0
  104. package/dist/solutions-components/demos/solution-spatial-ref.html +9 -16
  105. package/dist/solutions-components/demos/spatial-ref.html +53 -0
  106. package/dist/solutions-components/{p-64d29ba2.entry.js → p-0bc27ba7.entry.js} +2 -2
  107. package/dist/{collection/components/map-card/test/map-card.e2e.js → solutions-components/p-1b228f97.js} +2 -10
  108. package/dist/solutions-components/{p-9f11a403.entry.js → p-3c5c1487.entry.js} +1 -1
  109. package/dist/solutions-components/{p-a26711e8.js → p-469c8f8a.js} +1 -1
  110. package/dist/solutions-components/p-53bc5fc1.js +36 -0
  111. package/dist/solutions-components/p-5b8c8942.entry.js +21 -0
  112. package/dist/solutions-components/p-63c6fc29.entry.js +6 -0
  113. package/dist/solutions-components/p-64945b43.entry.js +18 -0
  114. package/dist/solutions-components/{p-c8d0ce92.js → p-698c6a56.js} +2 -2
  115. package/dist/solutions-components/{p-b9d29f30.entry.js → p-734cb206.entry.js} +1 -1
  116. package/dist/solutions-components/p-770bff06.entry.js +6 -0
  117. package/dist/solutions-components/p-7741dbab.entry.js +6 -0
  118. package/dist/solutions-components/p-80465067.entry.js +6 -0
  119. package/dist/solutions-components/p-846df994.entry.js +6 -0
  120. package/dist/solutions-components/p-b3f8d2cb.js +192 -0
  121. package/dist/solutions-components/p-c26d8b36.entry.js +6 -0
  122. package/dist/solutions-components/{p-57cf6784.entry.js → p-d22be647.entry.js} +1 -1
  123. package/dist/solutions-components/{p-4d942b0f.entry.js → p-f35147d5.entry.js} +1 -1
  124. package/dist/solutions-components/p-ff0d7712.js +44 -0
  125. package/dist/solutions-components/solutions-components.esm.js +1 -1
  126. package/dist/solutions-components/utils/mapViewUtils.ts +43 -20
  127. package/dist/solutions-components/utils/{templates.e2e.ts → test/templates.e2e.ts} +2 -2
  128. package/dist/types/components/crowdsource-manager/crowdsource-manager.d.ts +9 -1
  129. package/dist/types/components/floor-filter/floor-filter.d.ts +61 -0
  130. package/dist/types/components/layer-table/layer-table.d.ts +4 -0
  131. package/dist/types/components/map-card/map-card.d.ts +4 -0
  132. package/dist/types/components/map-tools/map-tools.d.ts +24 -0
  133. package/dist/types/components/solution-spatial-ref/solution-spatial-ref.d.ts +11 -93
  134. package/dist/types/components/spatial-ref/spatial-ref.d.ts +142 -0
  135. package/dist/types/components.d.ts +123 -16
  136. package/dist/types/preact.d.ts +8 -1
  137. package/package.json +6 -6
  138. package/dist/cjs/calcite-checkbox.cjs.entry.js +0 -136
  139. package/dist/collection/components/basemap-gallery/test/basemap-gallery.spec.js +0 -37
  140. package/dist/collection/components/buffer-tools/test/buffer-tools.e2e.js +0 -29
  141. package/dist/collection/components/buffer-tools/test/buffer-tools.spec.js +0 -160
  142. package/dist/collection/components/card-manager/test/card-manager.e2e.js +0 -29
  143. package/dist/collection/components/card-manager/test/card-manager.spec.js +0 -37
  144. package/dist/collection/components/crowdsource-manager/test/crowdsource-manager.e2e.js +0 -29
  145. package/dist/collection/components/crowdsource-manager/test/crowdsource-manager.spec.js +0 -37
  146. package/dist/collection/components/crowdsource-reporter/test/crowdsource-reporter.e2e.js +0 -29
  147. package/dist/collection/components/crowdsource-reporter/test/crowdsource-reporter.spec.js +0 -37
  148. package/dist/collection/components/deduct-calculator/test/deduct-calculator.e2e.js +0 -29
  149. package/dist/collection/components/deduct-calculator/test/deduct-calculator.spec.js +0 -37
  150. package/dist/collection/components/edit-card/test/edit-card.e2e.js +0 -14
  151. package/dist/collection/components/edit-card/test/edit-card.spec.js +0 -22
  152. package/dist/collection/components/info-card/test/info-card.e2e.js +0 -29
  153. package/dist/collection/components/info-card/test/info-card.spec.js +0 -37
  154. package/dist/collection/components/json-editor/test/json-editor.e2e.js +0 -36
  155. package/dist/collection/components/json-editor/test/json-editor.spec.js +0 -65
  156. package/dist/collection/components/layer-table/test/layer-table.spec.js +0 -37
  157. package/dist/collection/components/layout-manager/test/layout-manager.e2e.js +0 -29
  158. package/dist/collection/components/layout-manager/test/layout-manager.spec.js +0 -37
  159. package/dist/collection/components/list-item/test/list-item.e2e.js +0 -29
  160. package/dist/collection/components/list-item/test/list-item.spec.js +0 -37
  161. package/dist/collection/components/map-card/test/map-card.spec.js +0 -37
  162. package/dist/collection/components/map-draw-tools/test/map-draw-tools.e2e.js +0 -29
  163. package/dist/collection/components/map-draw-tools/test/map-draw-tools.spec.js +0 -37
  164. package/dist/collection/components/map-fullscreen/test/map-fullscreen.e2e.js +0 -29
  165. package/dist/collection/components/map-fullscreen/test/map-fullscreen.spec.js +0 -37
  166. package/dist/collection/components/map-layer-picker/test/map-layer-picker.e2e.js +0 -29
  167. package/dist/collection/components/map-layer-picker/test/map-layer-picker.spec.js +0 -114
  168. package/dist/collection/components/map-legend/test/map-legend.e2e.js +0 -14
  169. package/dist/collection/components/map-legend/test/map-legend.spec.js +0 -22
  170. package/dist/collection/components/map-picker/test/map-picker.e2e.js +0 -29
  171. package/dist/collection/components/map-picker/test/map-picker.spec.js +0 -37
  172. package/dist/collection/components/map-search/test/map-search.e2e.js +0 -29
  173. package/dist/collection/components/map-search/test/map-search.spec.js +0 -37
  174. package/dist/collection/components/map-select-tools/test/map-select-tools.e2e.js +0 -29
  175. package/dist/collection/components/map-select-tools/test/map-select-tools.spec.js +0 -366
  176. package/dist/collection/components/map-tools/test/map-tools.e2e.js +0 -29
  177. package/dist/collection/components/map-tools/test/map-tools.spec.js +0 -37
  178. package/dist/collection/components/pci-calculator/test/pci-calculator.e2e.js +0 -29
  179. package/dist/collection/components/pci-calculator/test/pci-calculator.spec.js +0 -37
  180. package/dist/collection/components/pdf-download/test/pdf-download.e2e.js +0 -76
  181. package/dist/collection/components/pdf-download/test/pdf-download.spec.js +0 -107
  182. package/dist/collection/components/public-notification/test/public-notification.spec.js +0 -161
  183. package/dist/collection/components/refine-selection/test/refine-selection.e2e.js +0 -14
  184. package/dist/collection/components/refine-selection/test/refine-selection.spec.js +0 -22
  185. package/dist/collection/components/solution-configuration/test/solution-configuration.e2e.js +0 -36
  186. package/dist/collection/components/solution-configuration/test/solution-configuration.spec.js +0 -119
  187. package/dist/collection/components/solution-contents/test/solution-contents.e2e.js +0 -94
  188. package/dist/collection/components/solution-contents/test/solution-contents.spec.js +0 -143
  189. package/dist/collection/components/solution-item/test/solution-item.e2e.js +0 -36
  190. package/dist/collection/components/solution-item/test/solution-item.spec.js +0 -77
  191. package/dist/collection/components/solution-item-details/test/solution-item-details.e2e.js +0 -36
  192. package/dist/collection/components/solution-item-details/test/solution-item-details.spec.js +0 -142
  193. package/dist/collection/components/solution-item-icon/test/solution-item-icon.e2e.js +0 -29
  194. package/dist/collection/components/solution-item-icon/test/solution-item-icon.spec.js +0 -39
  195. package/dist/collection/components/solution-item-sharing/test/solution-item-sharing.e2e.js +0 -36
  196. package/dist/collection/components/solution-item-sharing/test/solution-item-sharing.spec.js +0 -54
  197. package/dist/collection/components/solution-organization-variables/test/solution-organization-variables.e2e.js +0 -36
  198. package/dist/collection/components/solution-organization-variables/test/solution-organization-variables.spec.js +0 -65
  199. package/dist/collection/components/solution-resource-item/test/solution-resource-item.e2e.js +0 -36
  200. package/dist/collection/components/solution-resource-item/test/solution-resource-item.spec.js +0 -55
  201. package/dist/collection/components/solution-template-data/test/solution-template-data.e2e.js +0 -36
  202. package/dist/collection/components/solution-template-data/test/solution-template-data.spec.js +0 -60
  203. package/dist/collection/components/solution-variables/test/solution-variables.e2e.js +0 -36
  204. package/dist/collection/components/solution-variables/test/solution-variables.spec.js +0 -131
  205. package/dist/esm/calcite-checkbox.entry.js +0 -132
  206. package/dist/solutions-components/p-07d7e11f.entry.js +0 -6
  207. package/dist/solutions-components/p-16362eb4.js +0 -36
  208. package/dist/solutions-components/p-17d176b5.js +0 -230
  209. package/dist/solutions-components/p-1d9a5198.entry.js +0 -37
  210. package/dist/solutions-components/p-3707d9bd.entry.js +0 -6
  211. package/dist/solutions-components/p-4dbe8337.entry.js +0 -6
  212. package/dist/solutions-components/p-5ffaaaf4.entry.js +0 -6
  213. package/dist/solutions-components/p-736e76fb.entry.js +0 -17
  214. package/dist/solutions-components/p-99f1a767.entry.js +0 -6
  215. /package/dist/collection/components/{solution-spatial-ref → spatial-ref}/spatialreferences.js +0 -0
  216. /package/dist/types/components/{solution-spatial-ref → spatial-ref}/spatialreferences.d.ts +0 -0
@@ -5,10 +5,7 @@
5
5
  */
6
6
  'use strict';
7
7
 
8
- const index = require('./index-feeb7b6a.js');
9
- const interfaces = require('./interfaces-000be6de.js');
10
8
  const _commonjsHelpers = require('./_commonjsHelpers-384729db.js');
11
- const cleanUrl = require('./clean-url-d5326abb.js');
12
9
 
13
10
  /** @license
14
11
  * Copyright 2018 Esri
@@ -65,263 +62,6 @@ var EItemProgressStatus;
65
62
  })(EItemProgressStatus || (EItemProgressStatus = {}));
66
63
  //#endregion ---------------------------------------------------------------------------------------------------------//
67
64
 
68
- /* Copyright (c) 2018-2019 Environmental Systems Research Institute, Inc.
69
- * Apache-2.0 */
70
- /**
71
- * Returns an array with arrays of the given size.
72
- *
73
- * @param arr Array to split
74
- * @param size Size of every group
75
- */
76
- function chunkArray(arr, size) {
77
- const results = [];
78
- let index = 0;
79
- while (index < arr.length) {
80
- results.push(arr.slice(index, index + size));
81
- index += size;
82
- }
83
- return results;
84
- }
85
-
86
- /*! *****************************************************************************
87
- Copyright (c) Microsoft Corporation.
88
-
89
- Permission to use, copy, modify, and/or distribute this software for any
90
- purpose with or without fee is hereby granted.
91
-
92
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
93
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
94
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
95
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
96
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
97
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
98
- PERFORMANCE OF THIS SOFTWARE.
99
- ***************************************************************************** */
100
-
101
- var __assign = function() {
102
- __assign = Object.assign || function __assign(t) {
103
- for (var s, i = 1, n = arguments.length; i < n; i++) {
104
- s = arguments[i];
105
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
106
- }
107
- return t;
108
- };
109
- return __assign.apply(this, arguments);
110
- };
111
-
112
- /* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
113
- * Apache-2.0 */
114
- /**
115
- * Helper that returns the appropriate portal url for a given request. `requestOptions.portal` is given
116
- * precedence over `authentication.portal`. If neither `portal` nor `authentication` is present,
117
- * `www.arcgis.com/sharing/rest` is returned.
118
- *
119
- * @param requestOptions - Request options that may have authentication manager
120
- * @returns Portal url to be used in API requests
121
- */
122
- function getPortalUrl(requestOptions) {
123
- if (requestOptions === void 0) { requestOptions = {}; }
124
- // use portal in options if specified
125
- if (requestOptions.portal) {
126
- return cleanUrl.cleanUrl(requestOptions.portal);
127
- }
128
- // if auth was passed, use that portal
129
- if (requestOptions.authentication) {
130
- // the portal url is already scrubbed in the auth package
131
- return requestOptions.authentication.portal;
132
- }
133
- // default to arcgis.com
134
- return "https://www.arcgis.com/sharing/rest";
135
- }
136
-
137
- /* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
138
- * Apache-2.0 */
139
- /**
140
- * Serialize an item and its data into a json format accepted by the Portal API for create and update operations
141
- *
142
- * @param item Item to be serialized
143
- * @returns a formatted json object to be sent to Portal
144
- */
145
- function serializeItem(item) {
146
- // create a clone so we're not messing with the original
147
- var clone = JSON.parse(JSON.stringify(item));
148
- // binary data needs POSTed as a `file`
149
- // JSON object literals should be passed as `text`.
150
- if (clone.data) {
151
- (typeof Blob !== "undefined" && item.data instanceof Blob) ||
152
- // Node.js doesn't implement Blob
153
- item.data.constructor.name === "ReadStream"
154
- ? (clone.file = item.data)
155
- : (clone.text = item.data);
156
- delete clone.data;
157
- }
158
- return clone;
159
- }
160
- /**
161
- * `requestOptions.owner` is given priority, `requestOptions.item.owner` will be checked next. If neither are present, `authentication.getUserName()` will be used instead.
162
- */
163
- function determineOwner(requestOptions) {
164
- if (requestOptions.owner) {
165
- return Promise.resolve(requestOptions.owner);
166
- }
167
- else if (requestOptions.item && requestOptions.item.owner) {
168
- return Promise.resolve(requestOptions.item.owner);
169
- }
170
- else if (requestOptions.authentication &&
171
- requestOptions.authentication.getUsername) {
172
- return requestOptions.authentication.getUsername();
173
- }
174
- else {
175
- return Promise.reject(new Error("Could not determine the owner of this item. Pass the `owner`, `item.owner`, or `authentication` option."));
176
- }
177
- }
178
- /**
179
- * checks if the extent is a valid BBox (2 element array of coordinate pair arrays)
180
- * @param extent
181
- * @returns
182
- */
183
- function isBBox(extent) {
184
- return (Array.isArray(extent) &&
185
- Array.isArray(extent[0]) &&
186
- Array.isArray(extent[1]));
187
- }
188
- /**
189
- * Given a Bbox, convert it to a string. Some api endpoints expect a string
190
- *
191
- * @param {BBox} extent
192
- * @return {*} {string}
193
- */
194
- function bboxToString(extent) {
195
- return extent.join(",");
196
- }
197
-
198
- /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
199
- * Apache-2.0 */
200
- /**
201
- * ```js
202
- * import { updateItem } from "@esri/arcgis-rest-portal";
203
- * //
204
- * updateItem({
205
- * item: {
206
- * id: "3ef",
207
- * description: "A three hour tour"
208
- * },
209
- * authentication
210
- * })
211
- * .then(response)
212
- * ```
213
- * Update an Item. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/update-item.htm) for more information.
214
- *
215
- * @param requestOptions - Options for the request.
216
- * @returns A Promise that updates an item.
217
- */
218
- function updateItem$1(requestOptions) {
219
- return determineOwner(requestOptions).then(function (owner) {
220
- var url = requestOptions.folderId
221
- ? getPortalUrl(requestOptions) + "/content/users/" + owner + "/" + requestOptions.folderId + "/items/" + requestOptions.item.id + "/update"
222
- : getPortalUrl(requestOptions) + "/content/users/" + owner + "/items/" + requestOptions.item.id + "/update";
223
- // serialize the item into something Portal will accept
224
- requestOptions.params = __assign(__assign({}, requestOptions.params), serializeItem(requestOptions.item));
225
- // convert extent, if present, into a string from bbox
226
- // processParams was previously doing this sort of work,
227
- // however now we need to let array of arrays through
228
- // Thus for extents we need to move this logic here
229
- if (requestOptions.params.extent && isBBox(requestOptions.params.extent)) {
230
- requestOptions.params.extent = bboxToString(requestOptions.params.extent);
231
- }
232
- return cleanUrl.request(url, requestOptions);
233
- });
234
- }
235
- /**
236
- * ```js
237
- * import { updateItemResource } from "@esri/arcgis-rest-portal";
238
- * //
239
- * updateItemResource({
240
- * id: '3ef',
241
- * resource: file,
242
- * name: 'bigkahuna.jpg',
243
- * authentication
244
- * })
245
- * .then(response)
246
- * ```
247
- * Update a resource associated with an item. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/update-resources.htm) for more information.
248
- *
249
- * @param requestOptions - Options for the request
250
- * @returns A Promise that updates an item resource.
251
- */
252
- function updateItemResource(requestOptions) {
253
- return determineOwner(requestOptions).then(function (owner) {
254
- var url = getPortalUrl(requestOptions) + "/content/users/" + owner + "/items/" + requestOptions.id + "/updateResources";
255
- // mix in user supplied params
256
- requestOptions.params = __assign({ file: requestOptions.resource, fileName: requestOptions.name, resourcesPrefix: requestOptions.prefix, text: requestOptions.content }, requestOptions.params);
257
- // only override the access specified previously if 'private' is passed explicitly
258
- if (typeof requestOptions.private !== "undefined") {
259
- requestOptions.params.access = requestOptions.private
260
- ? "private"
261
- : "inherit";
262
- }
263
- return cleanUrl.request(url, requestOptions);
264
- });
265
- }
266
-
267
- /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
268
- * Apache-2.0 */
269
- /**
270
- * ```js
271
- * import { addItemResource } from "@esri/arcgis-rest-portal";
272
- * //
273
- * // Add a file resource
274
- * addItemResource({
275
- * id: '3ef',
276
- * resource: file,
277
- * name: 'bigkahuna.jpg',
278
- * authentication
279
- * })
280
- * .then(response)
281
- * //
282
- * // Add a text resource
283
- * addItemResource({
284
- * id: '4fg',
285
- * content: "Text content",
286
- * name: 'bigkahuna.txt',
287
- * authentication
288
- * })
289
- * .then(response)
290
- * ```
291
- * Add a resource associated with an item. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/add-resources.htm) for more information.
292
- *
293
- * @param requestOptions - Options for the request
294
- * @returns A Promise to add item resources.
295
- */
296
- function addItemResource(requestOptions) {
297
- return determineOwner(requestOptions).then(function (owner) {
298
- var url = getPortalUrl(requestOptions) + "/content/users/" + owner + "/items/" + requestOptions.id + "/addResources";
299
- requestOptions.params = __assign({ file: requestOptions.resource, fileName: requestOptions.name, resourcesPrefix: requestOptions.prefix, text: requestOptions.content, access: requestOptions.private ? "private" : "inherit" }, requestOptions.params);
300
- return cleanUrl.request(url, requestOptions);
301
- });
302
- }
303
-
304
- /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
305
- * Apache-2.0 */
306
- /**
307
- * Remove a resource associated with an item
308
- *
309
- * @param requestOptions - Options for the request
310
- * @returns A Promise that deletes an item resource.
311
- */
312
- function removeItemResource(requestOptions) {
313
- return determineOwner(requestOptions).then(function (owner) {
314
- var url = getPortalUrl(requestOptions) + "/content/users/" + owner + "/items/" + requestOptions.id + "/removeResources";
315
- // mix in user supplied params
316
- requestOptions.params = __assign(__assign({}, requestOptions.params), { resource: requestOptions.resource });
317
- // only override the deleteAll param specified previously if it is passed explicitly
318
- if (typeof requestOptions.deleteAll !== "undefined") {
319
- requestOptions.params.deleteAll = requestOptions.deleteAll;
320
- }
321
- return cleanUrl.request(url, requestOptions);
322
- });
323
- }
324
-
325
65
  var jszip_min = _commonjsHelpers.createCommonjsModule(function (module, exports) {
326
66
  /*!
327
67
 
@@ -2037,408 +1777,6 @@ var xss = FilterXSS;
2037
1777
  }
2038
1778
  } (lib$1, lib$1.exports));
2039
1779
 
2040
- /** @license
2041
- * Copyright 2020 Esri
2042
- *
2043
- * Licensed under the Apache License, Version 2.0 (the "License");
2044
- * you may not use this file except in compliance with the License.
2045
- * You may obtain a copy of the License at
2046
- *
2047
- * http://www.apache.org/licenses/LICENSE-2.0
2048
- *
2049
- * Unless required by applicable law or agreed to in writing, software
2050
- * distributed under the License is distributed on an "AS IS" BASIS,
2051
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2052
- * See the License for the specific language governing permissions and
2053
- * limitations under the License.
2054
- */
2055
- /**
2056
- * Supplies the File constructor for Microsoft Legacy Edge.
2057
- *
2058
- * @param fileBits Contents for file
2059
- * @param fileName Name for file
2060
- * @param options Bucket of options, euch as `type` for the MIME type; defaults to empty string for `type`
2061
- * @returns File or, for Microsoft Legacy Edge, Blob
2062
- * @see https://developer.mozilla.org/en-US/docs/Web/API/File/File
2063
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob
2064
- */
2065
- function new_File(fileBits, fileName, options) {
2066
- let file;
2067
- try {
2068
- // Modern browser
2069
- file = new File(fileBits, fileName, options);
2070
- }
2071
- catch (error) {
2072
- // Microsoft Legacy Edge
2073
- /* istanbul ignore next */
2074
- file = (function () {
2075
- if (typeof options === "undefined") {
2076
- // Microsoft Legacy Edge fails in karma if options is not defined
2077
- options = {
2078
- type: ""
2079
- };
2080
- }
2081
- const blob = new Blob(fileBits, options);
2082
- blob.lastModified = new Date();
2083
- blob.name = fileName;
2084
- return blob;
2085
- })();
2086
- }
2087
- return file;
2088
- }
2089
-
2090
- /** @license
2091
- * Copyright 2018 Esri
2092
- *
2093
- * Licensed under the Apache License, Version 2.0 (the "License");
2094
- * you may not use this file except in compliance with the License.
2095
- * You may obtain a copy of the License at
2096
- *
2097
- * http://www.apache.org/licenses/LICENSE-2.0
2098
- *
2099
- * Unless required by applicable law or agreed to in writing, software
2100
- * distributed under the License is distributed on an "AS IS" BASIS,
2101
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2102
- * See the License for the specific language governing permissions and
2103
- * limitations under the License.
2104
- */
2105
- /**
2106
- * Extracts JSON from a Blob.
2107
- *
2108
- * @param blob Blob to use as source
2109
- * @returns A promise that will resolve with JSON or null
2110
- */
2111
- function blobToJson(blob) {
2112
- return new Promise(resolve => {
2113
- blobToText(blob).then(blobContents => {
2114
- try {
2115
- resolve(JSON.parse(blobContents));
2116
- }
2117
- catch (err) {
2118
- resolve(null);
2119
- }
2120
- }, () => resolve(null));
2121
- });
2122
- }
2123
- /**
2124
- * Converts a Blob to a File.
2125
- *
2126
- * @param blob Blob to use as source
2127
- * @param filename Name to use for file
2128
- * @param mimeType MIME type to override blob's MIME type
2129
- * @returns File created out of Blob and filename
2130
- */
2131
- function blobToFile(blob, filename, mimeType) {
2132
- return blob
2133
- ? new_File([blob], filename ? filename : "", {
2134
- type: mimeType || blob.type
2135
- })
2136
- : null;
2137
- }
2138
- /**
2139
- * Extracts text from a Blob.
2140
- *
2141
- * @param blob Blob to use as source
2142
- * @returns A promise that will resolve with text read from blob
2143
- */
2144
- function blobToText(blob) {
2145
- return new Promise(resolve => {
2146
- const reader = new FileReader();
2147
- reader.onload = function (evt) {
2148
- // Disable needed because Node requires cast
2149
- // tslint:disable-next-line: no-unnecessary-type-assertion
2150
- const blobContents = evt.target.result;
2151
- resolve(blobContents ? blobContents : ""); // not handling ArrayContents variant
2152
- };
2153
- reader.readAsText(blob);
2154
- });
2155
- }
2156
- /**
2157
- * Checks that a URL path ends with a slash.
2158
- *
2159
- * @param url URL to check
2160
- * @returns URL, appended with slash if missing
2161
- */
2162
- function checkUrlPathTermination(url) {
2163
- return url ? (url.endsWith("/") ? url : url + "/") : url;
2164
- }
2165
- /**
2166
- * Gets a property out of a deeply nested object.
2167
- * Does not handle anything but nested object graph
2168
- *
2169
- * @param obj Object to retrieve value from
2170
- * @param path Path into an object, e.g., "data.values.webmap", where "data" is a top-level property
2171
- * in obj
2172
- * @returns Value at end of path
2173
- */
2174
- function getProp(obj, path) {
2175
- return path.split(".").reduce(function (prev, curr) {
2176
- /* istanbul ignore next no need to test undefined scenario */
2177
- return prev ? prev[curr] : undefined;
2178
- }, obj);
2179
- }
2180
- /**
2181
- * Sets a deeply nested property of an object.
2182
- * Creates the full path if it does not exist.
2183
- *
2184
- * @param obj Object to set value of
2185
- * @param path Path into an object, e.g., "data.values.webmap", where "data" is a top-level property in obj
2186
- * @param value The value to set at the end of the path
2187
- */
2188
- function setCreateProp(obj, path, value) {
2189
- const pathParts = path.split(".");
2190
- pathParts.reduce((a, b, c) => {
2191
- if (c === pathParts.length - 1) {
2192
- a[b] = value;
2193
- return value;
2194
- }
2195
- else {
2196
- if (!a[b]) {
2197
- a[b] = {};
2198
- }
2199
- return a[b];
2200
- }
2201
- }, obj);
2202
- }
2203
-
2204
- /**
2205
- * Gets a Blob from a web site.
2206
- *
2207
- * @param url Address of Blob
2208
- * @param authentication Credentials for the request
2209
- * @param requestOptions - Options for the request, including parameters relevant to the endpoint.
2210
- * @returns Promise that will resolve with Blob or an AGO-style JSON failure response
2211
- */
2212
- function getBlob(url, authentication, requestOptions = {}) {
2213
- if (!url) {
2214
- return Promise.reject("Url must be provided");
2215
- }
2216
- const blobRequestOptions = {
2217
- authentication: authentication,
2218
- rawResponse: true,
2219
- ...requestOptions
2220
- };
2221
- return cleanUrl.request(url, blobRequestOptions).then(response => {
2222
- return response.blob();
2223
- });
2224
- }
2225
-
2226
- /** @license
2227
- * Copyright 2018 Esri
2228
- *
2229
- * Licensed under the Apache License, Version 2.0 (the "License");
2230
- * you may not use this file except in compliance with the License.
2231
- * You may obtain a copy of the License at
2232
- *
2233
- * http://www.apache.org/licenses/LICENSE-2.0
2234
- *
2235
- * Unless required by applicable law or agreed to in writing, software
2236
- * distributed under the License is distributed on an "AS IS" BASIS,
2237
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2238
- * See the License for the specific language governing permissions and
2239
- * limitations under the License.
2240
- */
2241
- // ------------------------------------------------------------------------------------------------------------------ //
2242
- const ZIP_FILE_HEADER_SIGNATURE = "PK";
2243
- /**
2244
- * Gets a Blob from a web site and casts it as a file using the supplied name.
2245
- *
2246
- * @param url Address of Blob
2247
- * @param filename Name to use for file
2248
- * @param authentication Credentials for the request
2249
- * @returns Promise that will resolve with a File, undefined if the Blob is null, or an AGO-style JSON failure response
2250
- */
2251
- function getBlobAsFile(url, filename, authentication, ignoreErrors = [], mimeType) {
2252
- return new Promise((resolve, reject) => {
2253
- // Get the blob from the URL
2254
- getBlobCheckForError(url, authentication, ignoreErrors).then(blob => !blob ? resolve(null) : resolve(blobToFile(blob, filename, mimeType)), reject);
2255
- });
2256
- }
2257
- /**
2258
- * Gets a Blob from a web site and checks for a JSON error packet in the Blob.
2259
- *
2260
- * @param url Address of Blob
2261
- * @param authentication Credentials for the request
2262
- * @param ignoreErrors List of HTTP error codes that should be ignored
2263
- * @returns Promise that will resolve with Blob or an AGO-REST JSON failure response
2264
- */
2265
- function getBlobCheckForError(url, authentication, ignoreErrors = []) {
2266
- return new Promise((resolve, reject) => {
2267
- // Get the blob from the URL
2268
- getBlob(url, authentication).then(blob => {
2269
- // Reclassify text/plain blobs as needed
2270
- _fixTextBlobType(blob).then(adjustedBlob => {
2271
- if (adjustedBlob.type === "application/json") {
2272
- // Blob may be an error
2273
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
2274
- blobToJson(adjustedBlob).then((json) => {
2275
- // Check for valid JSON with an error
2276
- if (json?.error) {
2277
- const code = json.error.code;
2278
- if (code !== undefined && ignoreErrors.indexOf(code) >= 0) {
2279
- resolve(null); // Error, but ignored
2280
- }
2281
- else {
2282
- reject(json); // Other error; fail with error
2283
- }
2284
- }
2285
- else {
2286
- resolve(adjustedBlob);
2287
- }
2288
- });
2289
- }
2290
- else {
2291
- resolve(adjustedBlob);
2292
- }
2293
- }, reject);
2294
- }, reject);
2295
- });
2296
- }
2297
- /**
2298
- * Gets the data information of an AGO item in its JSON form.
2299
- *
2300
- * @param itemId Id of an item whose data information is sought
2301
- * @param filename Name to use for file
2302
- * @param authentication Credentials for the request to AGO
2303
- * @returns Promise that will resolve with JSON, or an AGO-style JSON failure response
2304
- */
2305
- function getItemDataAsJson(itemId, authentication) {
2306
- return new Promise(resolve => {
2307
- getItemDataBlob(itemId, authentication).then(blob => resolve(blobToJson(blob)), () => resolve(null));
2308
- });
2309
- }
2310
- /**
2311
- * Gets the data information of an AGO item in its raw (Blob) form.
2312
- *
2313
- * @param itemId Id of an item whose data information is sought
2314
- * @param authentication Credentials for the request to AGO
2315
- * @returns A promise that will resolve with the data Blob or null if the item doesn't have a data section
2316
- */
2317
- function getItemDataBlob(itemId, authentication) {
2318
- return new Promise(resolve => {
2319
- const url = getItemDataBlobUrl(itemId, authentication);
2320
- getBlobCheckForError(url, authentication, [400, 500]).then(blob => resolve(_fixTextBlobType(blob)), () => resolve(null));
2321
- });
2322
- }
2323
- /**
2324
- * Gets the URL to the data information of an AGO item in its raw (Blob) form.
2325
- *
2326
- * @param itemId Id of an item whose data information is sought
2327
- * @param authentication Credentials for the request to AGO
2328
- * @returns URL string
2329
- */
2330
- function getItemDataBlobUrl(itemId, authentication) {
2331
- return `${getPortalSharingUrlFromAuth(authentication)}/content/items/${itemId}/data`;
2332
- }
2333
- /**
2334
- * Extracts the portal sharing url from a supplied authentication.
2335
- *
2336
- * @param authentication Credentials for the request to AGO
2337
- * @returns Portal sharing url to be used in API requests, defaulting to `https://www.arcgis.com/sharing/rest`
2338
- */
2339
- function getPortalSharingUrlFromAuth(authentication) {
2340
- // If auth was passed, use that portal
2341
- return getProp(authentication, "portal") || "https://www.arcgis.com/sharing/rest";
2342
- }
2343
- function getThumbnailFile(url, filename, authentication) {
2344
- return new Promise(resolve => {
2345
- getBlobAsFile(url, filename, authentication, [500]).then(resolve, () => resolve(null));
2346
- });
2347
- }
2348
- // ------------------------------------------------------------------------------------------------------------------ //
2349
- /**
2350
- * Fixes the types of Blobs incorrectly typed as text/plain.
2351
- *
2352
- * @param blob Blob to check
2353
- * @returns Promise resolving to original Blob, unless it's originally typed as text/plain but is
2354
- * really JSON, ZIP, or XML
2355
- * @private
2356
- */
2357
- function _fixTextBlobType(blob) {
2358
- return new Promise((resolve, reject) => {
2359
- if (blob &&
2360
- blob.size > 0 &&
2361
- (blob.type.startsWith("text/plain") ||
2362
- blob.type.startsWith("application/json"))) {
2363
- blobToText(blob).then(blobText => {
2364
- // Convertible to JSON?
2365
- try {
2366
- JSON.parse(blobText);
2367
- // Yes; reclassify as JSON
2368
- resolve(new Blob([blob], { type: "application/json" }));
2369
- }
2370
- catch (ignored) {
2371
- // Nope; test for ZIP file
2372
- if (blobText.length > 4 &&
2373
- blobText.substr(0, 4) === ZIP_FILE_HEADER_SIGNATURE) {
2374
- // Yes; reclassify as ZIP
2375
- resolve(new Blob([blob], { type: "application/zip" }));
2376
- }
2377
- else if (blobText.startsWith("<")) {
2378
- // Reclassify as XML; since the blob started out as text/plain, it's more likely that is
2379
- // meant to be human-readable, so we'll use text/xml instead of application/xml
2380
- resolve(new Blob([blob], { type: "text/xml" }));
2381
- }
2382
- else {
2383
- // Leave as text
2384
- resolve(blob);
2385
- }
2386
- }
2387
- },
2388
- // Faulty blob
2389
- reject);
2390
- }
2391
- else {
2392
- // Empty or not typed as plain text, so simply return
2393
- if (blob) {
2394
- resolve(blob);
2395
- }
2396
- else {
2397
- reject();
2398
- }
2399
- }
2400
- });
2401
- }
2402
-
2403
- /** @license
2404
- * Copyright 2018 Esri
2405
- *
2406
- * Licensed under the Apache License, Version 2.0 (the "License");
2407
- * you may not use this file except in compliance with the License.
2408
- * You may obtain a copy of the License at
2409
- *
2410
- * http://www.apache.org/licenses/LICENSE-2.0
2411
- *
2412
- * Unless required by applicable law or agreed to in writing, software
2413
- * distributed under the License is distributed on an "AS IS" BASIS,
2414
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2415
- * See the License for the specific language governing permissions and
2416
- * limitations under the License.
2417
- */
2418
- /**
2419
- * Updates an item.
2420
- *
2421
- * @param itemInfo The base info of an item; note that this content will be serialized, which doesn't work
2422
- * for binary content
2423
- * @param authentication Credentials for request
2424
- * @param folderId Item's folder
2425
- * @param additionalParams Updates that are put under the `params` property, which is not serialized
2426
- * @return
2427
- */
2428
- function updateItem(itemInfo, authentication, folderId, additionalParams) {
2429
- return new Promise((resolve, reject) => {
2430
- const updateOptions = {
2431
- item: itemInfo,
2432
- folderId: folderId,
2433
- authentication: authentication,
2434
- params: {
2435
- ...(additionalParams ?? {})
2436
- }
2437
- };
2438
- updateItem$1(updateOptions).then(response => (response.success ? resolve(response) : reject(response)), err => reject(err));
2439
- });
2440
- }
2441
-
2442
1780
  /** @license
2443
1781
  * Copyright 2018 Esri
2444
1782
  *
@@ -2497,1039 +1835,5 @@ var SolutionResourceType;
2497
1835
  SolutionResourceType[SolutionResourceType["info"] = 5] = "info";
2498
1836
  })(SolutionResourceType || (SolutionResourceType = {}));
2499
1837
 
2500
- /** @license
2501
- * Copyright 2020 Esri
2502
- *
2503
- * Licensed under the Apache License, Version 2.0 (the "License");
2504
- * you may not use this file except in compliance with the License.
2505
- * You may obtain a copy of the License at
2506
- *
2507
- * http://www.apache.org/licenses/LICENSE-2.0
2508
- *
2509
- * Unless required by applicable law or agreed to in writing, software
2510
- * distributed under the License is distributed on an "AS IS" BASIS,
2511
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2512
- * See the License for the specific language governing permissions and
2513
- * limitations under the License.
2514
- */
2515
- /**
2516
- * Extracts an item's resource folder and filename from the filename used to store a copy in a storage item.
2517
- *
2518
- * @param storageResourceFilename Filename used to store the resource, metadata, or thumbnail of an item
2519
- * @param storageVersion Version of the Solution template
2520
- * @returns Folder and filename for storing information in an item, as well as the type (resource, metadata,
2521
- * or thumbnail) of the information; the folder property is only meaningful for the resource type
2522
- * @see generateResourceStorageFilename
2523
- * @see generateMetadataStorageFilename
2524
- * @see generateThumbnailStorageFilename
2525
- * @see convertItemResourceToStorageResource
2526
- */
2527
- function convertStorageResourceToItemResource(storageResourceFilename, storageVersion = 0) {
2528
- const nameParts = storageResourceFilename.split("/");
2529
- let filename = nameParts.pop();
2530
- let folder = "";
2531
- const firstPrefixPart = nameParts.shift(); // undefined if there's no folder
2532
- // Handle special "folders"
2533
- let type = exports.EFileType.Resource;
2534
- if (firstPrefixPart) {
2535
- if (firstPrefixPart.endsWith("_info_thumbnail")) {
2536
- type = exports.EFileType.Thumbnail;
2537
- }
2538
- else if (firstPrefixPart.endsWith("_info_metadata")) {
2539
- type = exports.EFileType.Metadata;
2540
- filename = "metadata.xml";
2541
- }
2542
- else if (firstPrefixPart.endsWith("_info_data")) {
2543
- type = exports.EFileType.Data;
2544
- }
2545
- else if (firstPrefixPart.endsWith("_info_dataz")) {
2546
- filename = filename.replace(/\.zip$/, "");
2547
- type = exports.EFileType.Data;
2548
- // Otherwise, strip off item id
2549
- }
2550
- else if (storageVersion < 1) {
2551
- // Version 0
2552
- const folderStart = firstPrefixPart.indexOf("_");
2553
- if (folderStart > 0) {
2554
- folder = firstPrefixPart.substr(folderStart + 1);
2555
- }
2556
- }
2557
- else {
2558
- // Version ≥ 1
2559
- folder = nameParts.join("/"); // folder is optional, in which case this will be ""
2560
- }
2561
- }
2562
- return { type, folder, filename };
2563
- }
2564
-
2565
- /** @license
2566
- * Copyright 2021 Esri
2567
- *
2568
- * Licensed under the Apache License, Version 2.0 (the "License");
2569
- * you may not use this file except in compliance with the License.
2570
- * You may obtain a copy of the License at
2571
- *
2572
- * http://www.apache.org/licenses/LICENSE-2.0
2573
- *
2574
- * Unless required by applicable law or agreed to in writing, software
2575
- * distributed under the License is distributed on an "AS IS" BASIS,
2576
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2577
- * See the License for the specific language governing permissions and
2578
- * limitations under the License.
2579
- */
2580
- // ------------------------------------------------------------------------------------------------------------------ //
2581
- /**
2582
- * Generates IAssociatedFileCopyResults object.
2583
- *
2584
- * @param fileInfo Info about item that was to be copied
2585
- * @param fetchedFromSource Status of fetching item from source
2586
- * @param copiedToDestination Status of copying item to destination
2587
- * @returns IAssociatedFileCopyResults object
2588
- */
2589
- function createCopyResults(fileInfo, fetchedFromSource, copiedToDestination) {
2590
- return {
2591
- ...fileInfo,
2592
- fetchedFromSource,
2593
- copiedToDestination
2594
- };
2595
- }
2596
-
2597
- /** @license
2598
- * Copyright 2021 Esri
2599
- *
2600
- * Licensed under the Apache License, Version 2.0 (the "License");
2601
- * you may not use this file except in compliance with the License.
2602
- * You may obtain a copy of the License at
2603
- *
2604
- * http://www.apache.org/licenses/LICENSE-2.0
2605
- *
2606
- * Unless required by applicable law or agreed to in writing, software
2607
- * distributed under the License is distributed on an "AS IS" BASIS,
2608
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2609
- * See the License for the specific language governing permissions and
2610
- * limitations under the License.
2611
- */
2612
- // ------------------------------------------------------------------------------------------------------------------ //
2613
- /**
2614
- * Copies a resource into a zipfile.
2615
- *
2616
- * @param file Information about the source and destination of the file such as its URL, folder, filename
2617
- * @param zipInfo Information about a zipfile such as its name and its zip object
2618
- * @returns The result of the copy
2619
- */
2620
- function copyResourceIntoZip(file, zipInfo) {
2621
- // Add it to the zip
2622
- if (file.folder) {
2623
- zipInfo.zip
2624
- .folder(file.folder)
2625
- .file(file.filename, file.file, { binary: true });
2626
- }
2627
- else {
2628
- zipInfo.zip.file(file.filename, file.file, { binary: true });
2629
- }
2630
- zipInfo.filelist.push(file);
2631
- return createCopyResults(file, true);
2632
- }
2633
-
2634
- /** @license
2635
- * Copyright 2021 Esri
2636
- *
2637
- * Licensed under the Apache License, Version 2.0 (the "License");
2638
- * you may not use this file except in compliance with the License.
2639
- * You may obtain a copy of the License at
2640
- *
2641
- * http://www.apache.org/licenses/LICENSE-2.0
2642
- *
2643
- * Unless required by applicable law or agreed to in writing, software
2644
- * distributed under the License is distributed on an "AS IS" BASIS,
2645
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2646
- * See the License for the specific language governing permissions and
2647
- * limitations under the License.
2648
- */
2649
- // ------------------------------------------------------------------------------------------------------------------ //
2650
- /**
2651
- * Copies a zipfile into an AGO item.
2652
- *
2653
- * @param zipInfo Information about a zipfile such as its name and its zip object
2654
- * @param destinationItemId Id of item to receive copy of resource/metadata/thumbnail
2655
- * @param destinationAuthentication Credentials for the request to the storage
2656
- * @returns A promise which resolves to the result of the copy
2657
- */
2658
- function copyZipIntoItem(zipInfo, destinationItemId, destinationAuthentication) {
2659
- return new Promise(resolve => {
2660
- zipInfo.zip
2661
- .generateAsync({ type: "blob" })
2662
- .then((content) => {
2663
- return blobToFile(content, zipInfo.filename, "application/zip");
2664
- })
2665
- .then((zipfile) => {
2666
- const addResourceOptions = {
2667
- id: destinationItemId,
2668
- resource: zipfile,
2669
- authentication: destinationAuthentication,
2670
- params: {
2671
- archive: true
2672
- }
2673
- };
2674
- return addItemResource(addResourceOptions);
2675
- })
2676
- .then(() => resolve(createCopyResults(zipInfo, true, true)), () => resolve(createCopyResults(zipInfo, true, false)) // unable to add resource
2677
- );
2678
- });
2679
- }
2680
-
2681
- /** @license
2682
- * Copyright 2021 Esri
2683
- *
2684
- * Licensed under the Apache License, Version 2.0 (the "License");
2685
- * you may not use this file except in compliance with the License.
2686
- * You may obtain a copy of the License at
2687
- *
2688
- * http://www.apache.org/licenses/LICENSE-2.0
2689
- *
2690
- * Unless required by applicable law or agreed to in writing, software
2691
- * distributed under the License is distributed on an "AS IS" BASIS,
2692
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2693
- * See the License for the specific language governing permissions and
2694
- * limitations under the License.
2695
- */
2696
- // ------------------------------------------------------------------------------------------------------------------ //
2697
- /**
2698
- * Copies the files for storing the resources, metadata, and thumbnail of an item or group to a storage item
2699
- * with a specified path by collecting files into zip files.
2700
- *
2701
- * @param files List of item files' URLs and folder/filenames for storing the files
2702
- * @param destinationItemId Id of item to receive copy of resource/metadata/thumbnail
2703
- * @param destinationAuthentication Credentials for the request to the storage
2704
- * @param filesPerZip Number of files to include per zip file; AGO limits zips to 50 files
2705
- * @returns A promise which resolves to a list of the result of the copies
2706
- */
2707
- function copyFilesAsResources(files, destinationItemId, destinationAuthentication, filesPerZip = 40) {
2708
- return new Promise(resolve => {
2709
- let awaitAllItems = [];
2710
- const zipInfos = [];
2711
- if (files.length > 0) {
2712
- // Bundle the resources into chunked zip updates because AGO tends to have problems with
2713
- // many updates in a row to the same item: it claims success despite randomly failing.
2714
- // Note that AGO imposes a limit of 50 files per zip, so we break the list of resource
2715
- // file info into chunks below this threshold and start a zip for each
2716
- // https://developers.arcgis.com/rest/users-groups-and-items/add-resources.htm
2717
- const chunkedResourceFiles = chunkArray(files, filesPerZip);
2718
- chunkedResourceFiles.forEach((chunk, index) => {
2719
- // Create a zip for this chunk
2720
- const zipInfo = {
2721
- filename: `resources${index}.zip`,
2722
- zip: new jszip_min(),
2723
- filelist: []
2724
- };
2725
- awaitAllItems = awaitAllItems.concat(chunk.map(file => copyResourceIntoZip(file, zipInfo)));
2726
- zipInfos.push(zipInfo);
2727
- });
2728
- }
2729
- if (awaitAllItems.length > 0) {
2730
- // Wait until the Resource zip file(s) are prepared
2731
- void Promise.all(awaitAllItems).then((results) => {
2732
- // We have three types of results:
2733
- // | fetchedFromSource | copiedToDestination | interpretation | |
2734
- // +-------------------+---------------------+------------------------------------------------+
2735
- // | false | * | could not fetch file from source |
2736
- // | true | true | file has been fetched and sent to AGO |
2737
- // | true | undefined | file has been fetched and will be sent via zip |
2738
- // Filter out copiedToDestination===undefined; we'll get their status when we send their zip
2739
- results = results.filter((result) => !(result.fetchedFromSource &&
2740
- typeof result.copiedToDestination === "undefined"));
2741
- // Now send the resources to AGO
2742
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
2743
- _copyAssociatedFileZips(zipInfos, destinationItemId, destinationAuthentication).then((zipResults) => {
2744
- resolve(results.concat(zipResults));
2745
- });
2746
- });
2747
- }
2748
- else {
2749
- // No data, metadata, or resources to send; we're done
2750
- resolve([]);
2751
- }
2752
- });
2753
- }
2754
- /**
2755
- * Copies one or more zipfiles to a storage item.
2756
- *
2757
- * @param zipInfos List of zip files containing files to store
2758
- * @param destinationItemId Id of item to receive copy of resource/metadata/thumbnail
2759
- * @param destinationAuthentication Credentials for the request to the storage
2760
- * @returns A promise which resolves to a list of the result of the copies
2761
- * @private
2762
- */
2763
- function _copyAssociatedFileZips(zipInfos, destinationItemId, destinationAuthentication) {
2764
- return new Promise(resolve => {
2765
- const results = [];
2766
- // Filter out empty zips, which can happen when none of the files in the chunk going into a zip
2767
- // can be fetched; e.g., the only file is metadata.xml, and the source item doesn't have metadata
2768
- const nonEmptyZipInfos = zipInfos.filter((zipInfo) => Object.keys(zipInfo.zip.files).length > 0);
2769
- if (nonEmptyZipInfos.length > 0) {
2770
- // Send the zip(s) to AGO
2771
- void _sendZipsSeriallyToItem(nonEmptyZipInfos, destinationItemId, destinationAuthentication).then((zipResults) => {
2772
- resolve(zipResults);
2773
- });
2774
- }
2775
- else {
2776
- // No resources to send; we're done
2777
- resolve(results);
2778
- }
2779
- });
2780
- }
2781
- /**
2782
- * Copies one or more zipfiles to a storage item in a serial fashion, waiting a bit between sends.
2783
- *
2784
- * @param zipInfos List of zip files containing files to store
2785
- * @param destinationItemId Id of item to receive copy of resource/metadata/thumbnail
2786
- * @param destinationAuthentication Credentials for the request to the storage
2787
- * @returns A promise which resolves to a list of the result of the copies
2788
- */
2789
- function _sendZipsSeriallyToItem(zipInfos, destinationItemId, destinationAuthentication) {
2790
- return new Promise(resolve => {
2791
- let allResults = [];
2792
- // Remove zip from bottom of list
2793
- const zipInfoToSend = zipInfos.pop();
2794
- // Send predecessors in list
2795
- let sendOthersPromise = Promise.resolve([]);
2796
- if (zipInfos.length > 0) {
2797
- sendOthersPromise = _sendZipsSeriallyToItem(zipInfos, destinationItemId, destinationAuthentication);
2798
- }
2799
- void sendOthersPromise
2800
- .then((response) => {
2801
- allResults = response;
2802
- // Stall a little to give AGO time to catch up
2803
- return new Promise(resolveSleep => {
2804
- setTimeout(() => resolveSleep(), 1000);
2805
- });
2806
- })
2807
- .then(() => {
2808
- // Now send the zip removed from bottom of the input list
2809
- return copyZipIntoItem(zipInfoToSend, destinationItemId, destinationAuthentication);
2810
- })
2811
- .then((zipResult) => {
2812
- // Save the result of copying this zip as a status for each of the files that it contains
2813
- zipResult.filelist.forEach((fileInfo) => {
2814
- allResults.push(createCopyResults(fileInfo, true, zipResult.copiedToDestination));
2815
- });
2816
- resolve(allResults);
2817
- });
2818
- });
2819
- }
2820
-
2821
- /** @license
2822
- * Copyright 2018 Esri
2823
- *
2824
- * Licensed under the Apache License, Version 2.0 (the "License");
2825
- * you may not use this file except in compliance with the License.
2826
- * You may obtain a copy of the License at
2827
- *
2828
- * http://www.apache.org/licenses/LICENSE-2.0
2829
- *
2830
- * Unless required by applicable law or agreed to in writing, software
2831
- * distributed under the License is distributed on an "AS IS" BASIS,
2832
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2833
- * See the License for the specific language governing permissions and
2834
- * limitations under the License.
2835
- */
2836
- /**
2837
- * Copies the files for storing the resources, metadata, and thumbnail of an item or group to a storage item
2838
- * with a specified path.
2839
- *
2840
- * @param files List of item files and paths for storing the files
2841
- * @param storageItemId Id of item to receive copy of resource/metadata
2842
- * @param storageAuthentication Credentials for the request to the storage
2843
- * @returns A promise which resolves to a list of the filenames under which the resource/metadata are stored
2844
- */
2845
- function copyFilesToStorageItem(files, storageItemId, storageAuthentication) {
2846
- return new Promise(resolve => {
2847
- // tslint:disable-next-line: no-floating-promises
2848
- void copyFilesAsResources(files, storageItemId, storageAuthentication).then((results) => {
2849
- resolve(results
2850
- // Filter out failures
2851
- .filter((result) => result.fetchedFromSource && result.copiedToDestination)
2852
- // Return folder and filename in storage item's resources
2853
- .map((result) => result.folder + "/" + result.filename));
2854
- });
2855
- });
2856
- }
2857
- /**
2858
- * Generates the URL for reading an item's resource given the filename of the resource.
2859
- *
2860
- * @param sourcePortalSharingUrl Server/sharing
2861
- * @param itemId Id of item
2862
- * @param sourceResourceFilename Either filename or folder/filename to resource
2863
- * @returns URL string
2864
- */
2865
- function generateSourceResourceUrl(sourcePortalSharingUrl, itemId, sourceResourceFilename) {
2866
- return (checkUrlPathTermination(sourcePortalSharingUrl) +
2867
- "content/items/" +
2868
- itemId +
2869
- "/resources/" +
2870
- sourceResourceFilename);
2871
- }
2872
- /**
2873
- * Generates a list of full URLs and folder/filename combinations used to store the resources, metadata,
2874
- * and thumbnail of an item.
2875
- *
2876
- * @param portalSharingUrl Server/sharing
2877
- * @param storageItemId Id of storage item
2878
- * @param resourceFilenames List of resource filenames for an item, e.g., ["file1", "myFolder/file2"]
2879
- * @param storageVersion Version of the Solution template
2880
- * @returns List of item files' URLs and folder/filenames for storing the files
2881
- */
2882
- function generateStorageFilePaths(portalSharingUrl, storageItemId, resourceFilenames = [], storageVersion = 0) {
2883
- return resourceFilenames.map(resourceFilename => {
2884
- return {
2885
- url: generateSourceResourceUrl(portalSharingUrl, storageItemId, resourceFilename),
2886
- ...convertStorageResourceToItemResource(resourceFilename, storageVersion)
2887
- };
2888
- });
2889
- }
2890
- function isSupportedFileType(filename) {
2891
- // Supported file formats are: .json, .xml, .txt, .png, .pbf, .zip, .jpeg, .jpg, .gif, .bmp, .gz, .svg,
2892
- // .svgz, .geodatabase (https://developers.arcgis.com/rest/users-groups-and-items/add-resources.htm)
2893
- const filenameExtension = filename.match(/\.([a-z]+)$/i);
2894
- const supportedExtensions = "|.json|.xml|.txt|.png|.pbf|.zip|.jpeg|.jpg|.gif|.bmp|.gz|.svg|.svgz|.geodatabase|";
2895
- return (!!filenameExtension &&
2896
- supportedExtensions.indexOf("|" + filenameExtension[0] + "|") >= 0);
2897
- }
2898
- /**
2899
- * Gets the thumbnail of an item or group.
2900
- *
2901
- * @param authentication Credentials for the request to the storage
2902
- * @param filePaths List of item files' URLs and folder/filenames for storing the files
2903
- * @returns A promise which resolves to a boolean indicating if the copies were successful
2904
- */
2905
- function getThumbnailFromStorageItem(authentication, filePaths) {
2906
- let thumbnailUrl;
2907
- let thumbnailFilename;
2908
- filePaths.forEach(path => {
2909
- if (path.type === exports.EFileType.Thumbnail) {
2910
- thumbnailUrl = path.url;
2911
- thumbnailFilename = path.filename;
2912
- }
2913
- });
2914
- if (!thumbnailUrl) {
2915
- return Promise.resolve(null);
2916
- }
2917
- return getThumbnailFile(thumbnailUrl, thumbnailFilename, authentication);
2918
- }
2919
- /**
2920
- * Removes the item's resource that matches the filename with new content
2921
- *
2922
- * @param itemId Id of the item to remove
2923
- * @param filename Name of the resource file to remove
2924
- * @param authentication Credentials for the request to the storage
2925
- * @returns A promise which resolves with a success true/false response
2926
- */
2927
- function removeItemResourceFile(itemId, filename, authentication) {
2928
- return removeItemResource({
2929
- id: itemId,
2930
- resource: filename,
2931
- authentication: authentication
2932
- });
2933
- }
2934
- /**
2935
- * Updates the item's resource that matches the filename with new content
2936
- *
2937
- * @param itemId Id of the item to update
2938
- * @param filename Name of the resource file to update; prefix optional (e.g., a/b/file.txt)
2939
- * @param resource The new content to update the resource with
2940
- * @param authentication Credentials for the request to the storage
2941
- * @returns A promise which resolves with a success true/false response
2942
- */
2943
- function updateItemResourceFile(itemId, filename, resource, authentication) {
2944
- // Prefix has to be specified separately
2945
- const prefixedFilenameParts = filename.split("/");
2946
- const prefix = prefixedFilenameParts.length > 1 ? prefixedFilenameParts.slice(0, prefixedFilenameParts.length - 1).join("/") : undefined;
2947
- const suffix = prefixedFilenameParts[prefixedFilenameParts.length - 1];
2948
- return updateItemResource({
2949
- id: itemId,
2950
- prefix: prefix,
2951
- name: suffix,
2952
- resource,
2953
- authentication: authentication
2954
- });
2955
- }
2956
-
2957
- /** @license
2958
- * Copyright 2022 Esri
2959
- *
2960
- * Licensed under the Apache License, Version 2.0 (the "License");
2961
- * you may not use this file except in compliance with the License.
2962
- * You may obtain a copy of the License at
2963
- *
2964
- * http://www.apache.org/licenses/LICENSE-2.0
2965
- *
2966
- * Unless required by applicable law or agreed to in writing, software
2967
- * distributed under the License is distributed on an "AS IS" BASIS,
2968
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2969
- * See the License for the specific language governing permissions and
2970
- * limitations under the License.
2971
- */
2972
- const EmptySolutionStore = {
2973
- solutionItemId: "",
2974
- defaultWkid: undefined,
2975
- solutionData: { metadata: {}, templates: [] },
2976
- templateEdits: {},
2977
- featureServices: [],
2978
- spatialReferenceInfo: {
2979
- enabled: false,
2980
- services: {},
2981
- spatialReference: undefined
2982
- }
2983
- };
2984
- class SolutionStore {
2985
- /**
2986
- * Creates singleton instance when accessed; default export from module.
2987
- *
2988
- * @returns Static instance of the class
2989
- */
2990
- static get Store() {
2991
- return this._instance || (this._instance = new this());
2992
- }
2993
- /**
2994
- * Creates an empty store.
2995
- *
2996
- * @protected
2997
- */
2998
- constructor() {
2999
- this._hasChanges = false;
3000
- this._store = index.createStore(Object.assign({}, EmptySolutionStore));
3001
- }
3002
- /**
3003
- * Returns the stored information of an item.
3004
- *
3005
- * @param itemId Id of item to fetch
3006
- *
3007
- * @returns Item information or `undefined` if not found
3008
- */
3009
- getItemInfo(itemId) {
3010
- const templates = this._store.get("solutionData").templates;
3011
- let template;
3012
- templates.some((t) => {
3013
- if (itemId == t.itemId) {
3014
- template = t;
3015
- return true;
3016
- }
3017
- return false;
3018
- });
3019
- return template;
3020
- }
3021
- /**
3022
- * Returns a top-level store property: solutionItemId, defaultWkid, etc.
3023
- *
3024
- * @param propName Name of property
3025
- *
3026
- * @returns Value of property
3027
- */
3028
- getStoreInfo(propName) {
3029
- return this._store.get(propName);
3030
- }
3031
- /**
3032
- * Loads a Solution into the store from AGO.
3033
- *
3034
- * @param solutionItemId Id of the solution represented in the store
3035
- * @param authentication Credentials for fetching information to be loaded into the store
3036
- *
3037
- * @returns Promise that resolves when task is done
3038
- */
3039
- async loadSolution(solutionItemId, authentication) {
3040
- this._authentication = authentication;
3041
- const solutionData = await getItemDataAsJson(solutionItemId, authentication);
3042
- if (solutionData) {
3043
- const defaultWkid = getProp(solutionData, "params.wkid.default");
3044
- await this._prepareSolutionItemsForEditing(solutionItemId, solutionData.templates, authentication);
3045
- const featureServices = this._getFeatureServices(solutionData.templates);
3046
- const spatialReferenceInfo = this._getSpatialReferenceInfo(featureServices, defaultWkid);
3047
- this._store.set("solutionItemId", solutionItemId);
3048
- this._store.set("defaultWkid", defaultWkid);
3049
- this._store.set("solutionData", solutionData);
3050
- this._store.set("featureServices", featureServices);
3051
- this._store.set("spatialReferenceInfo", spatialReferenceInfo);
3052
- }
3053
- this._flagStoreHasChanges(false);
3054
- }
3055
- /**
3056
- * Queues the replacement of the thumbnail associated with a template item in the store.
3057
- *
3058
- * @param itemEdit Details of the template to modify, containing the new thumbnail in the `thumbnail`
3059
- * property
3060
- */
3061
- replaceItemThumbnail(itemEdit) {
3062
- // Flag the current thumbnail and any replacements for removal
3063
- itemEdit.resourceFilePaths.forEach((path) => {
3064
- if (path.type === exports.EFileType.Thumbnail) {
3065
- if (path.updateType === interfaces.EUpdateType.None) {
3066
- // Existing thumbnail not yet flagged for removal
3067
- path.updateType = interfaces.EUpdateType.Remove;
3068
- }
3069
- else if (path.updateType === interfaces.EUpdateType.Add || path.updateType === interfaces.EUpdateType.Update) {
3070
- // An earlier replacement
3071
- path.updateType = interfaces.EUpdateType.Obsolete;
3072
- }
3073
- }
3074
- });
3075
- // Remove any replacements already queued
3076
- itemEdit.resourceFilePaths =
3077
- itemEdit.resourceFilePaths.filter((path) => path.updateType != interfaces.EUpdateType.Obsolete);
3078
- // Add the new thumbnail to the store item
3079
- itemEdit.resourceFilePaths.push({
3080
- blob: itemEdit.thumbnail,
3081
- filename: itemEdit.thumbnail.name,
3082
- type: exports.EFileType.Thumbnail,
3083
- updateType: interfaces.EUpdateType.Add
3084
- });
3085
- // Update the store
3086
- this.setItemInfo(itemEdit);
3087
- }
3088
- /**
3089
- * Writes a Solution into AGO from the store. Must use `loadSolution` to continue with solution.
3090
- *
3091
- * @returns Promise that resolves when task is done
3092
- */
3093
- async saveSolution() {
3094
- // Update the templates in the original solution item data
3095
- const solutionItemId = this._store.get("solutionItemId");
3096
- const solutionData = this._store.get("solutionData");
3097
- const spatialReferenceInfo = this._store.get("spatialReferenceInfo");
3098
- await this._prepareSolutionItemsForStorage(solutionItemId, solutionData.templates, this._authentication);
3099
- const updatedDefaultWkid = this._setSpatialReferenceInfo(spatialReferenceInfo, solutionData.templates);
3100
- if (updatedDefaultWkid) {
3101
- setCreateProp(solutionData, "params.wkid", {
3102
- "label": "Spatial Reference",
3103
- "default": updatedDefaultWkid,
3104
- "valueType": "spatialReference",
3105
- "attributes": {
3106
- "required": "true"
3107
- }
3108
- });
3109
- }
3110
- else {
3111
- setCreateProp(solutionData, "params.wkid", {});
3112
- }
3113
- const itemInfo = {
3114
- id: solutionItemId,
3115
- text: solutionData
3116
- };
3117
- await updateItem(itemInfo, this._authentication);
3118
- }
3119
- /**
3120
- * Stores information for item.
3121
- *
3122
- * @param itemEdit Item information
3123
- */
3124
- setItemInfo(itemEdit) {
3125
- const solutionData = this._store.get("solutionData");
3126
- const templates = solutionData.templates;
3127
- templates.some((t) => {
3128
- if (itemEdit.itemId == t.itemId) {
3129
- t = itemEdit;
3130
- this._store.set("solutionData", solutionData);
3131
- this._flagStoreHasChanges(true);
3132
- return true;
3133
- }
3134
- return false;
3135
- });
3136
- }
3137
- /**
3138
- * Sets a top-level store property: solutionItemId, defaultWkid, etc.
3139
- *
3140
- * @param propName Name of property
3141
- * @param value Value of property
3142
- */
3143
- setStoreInfo(propName, value) {
3144
- this._store.set(propName, value);
3145
- this._flagStoreHasChanges(true);
3146
- }
3147
- //------------------------------------------------------------------------------------------------------------------//
3148
- /** Provides access to protected methods for unit testing.
3149
- *
3150
- * @param methodName Name of protected method to run
3151
- * @param arg1 First argument to forward to method, e.g., for "_prepareSolutionItemsForEditing", `solutionItemId`
3152
- * @param arg2 Second argument to forward to method, e.g., for "_prepareSolutionItemsForEditing", `templates`
3153
- * @param arg3 Third argument to forward to method, e.g., for "_prepareSolutionItemsForEditing", `authentication`
3154
- *
3155
- * @returns
3156
- */
3157
- _testAccess(methodName, arg1, arg2, arg3) {
3158
- switch (methodName) {
3159
- case "_emptyTheStore":
3160
- this._emptyTheStore();
3161
- break;
3162
- case "_getFeatureServices":
3163
- return this._getFeatureServices(arg1);
3164
- case "_getItemsSharedWithThisGroup":
3165
- return this._getItemsSharedWithThisGroup(arg1, arg2);
3166
- case "_getResourceFilePaths":
3167
- return this._getResourceFilePaths(arg1, arg2, arg3);
3168
- case "_getResourceStorageName":
3169
- return this._getResourceStorageName(arg1, arg2);
3170
- case "_getSpatialReferenceInfo":
3171
- return this._getSpatialReferenceInfo(arg1, arg2);
3172
- case "_prepareSolutionItemsForEditing":
3173
- return this._prepareSolutionItemsForEditing(arg1, arg2, arg3);
3174
- case "_prepareSolutionItemsForStorage":
3175
- return this._prepareSolutionItemsForStorage(arg1, arg2, arg3);
3176
- case "_setSpatialReferenceInfo":
3177
- return this._setSpatialReferenceInfo(arg1, arg2);
3178
- case "_splitFilename":
3179
- return this._splitFilename(arg1);
3180
- }
3181
- return null;
3182
- }
3183
- /**
3184
- * Returns the store to the empty state.
3185
- *
3186
- * @protected
3187
- */
3188
- _emptyTheStore() {
3189
- this._store.set("solutionItemId", EmptySolutionStore.solutionItemId);
3190
- this._store.set("defaultWkid", EmptySolutionStore.defaultWkid);
3191
- this._store.set("solutionData", EmptySolutionStore.solutionData);
3192
- this._store.set("templateEdits", EmptySolutionStore.templateEdits);
3193
- this._store.set("featureServices", EmptySolutionStore.featureServices);
3194
- this._store.set("spatialReferenceInfo", EmptySolutionStore.spatialReferenceInfo);
3195
- }
3196
- /**
3197
- * Sets the store's flag indicating if it has changes and dispatches an event when
3198
- * the flag value changes.
3199
- *
3200
- * @param flagHasChanges Current state of change in the store; if it doesn't match the value saved in this
3201
- * object, an event is dispatched with the new value and the saved value is updated
3202
- *
3203
- * @protected
3204
- */
3205
- _flagStoreHasChanges(flagHasChanges) {
3206
- // Event for notifying if the store has changes or not
3207
- if (this._hasChanges !== flagHasChanges) {
3208
- window.dispatchEvent(new CustomEvent("solutionStoreHasChanges", {
3209
- detail: flagHasChanges,
3210
- bubbles: true,
3211
- cancelable: false,
3212
- composed: true
3213
- }));
3214
- }
3215
- this._hasChanges = flagHasChanges;
3216
- }
3217
- /**
3218
- * Gets a list of Feature Services that are not views.
3219
- *
3220
- * @param templates A list of item templates from the solution
3221
- *
3222
- * @returns a list of feature services
3223
- *
3224
- * @protected
3225
- */
3226
- _getCustomizableFeatureServices(templates) {
3227
- return templates.reduce((prev, cur) => {
3228
- if (cur.type === "Feature Service" && cur.item.typeKeywords.indexOf("View Service") < 0) {
3229
- prev.push(cur);
3230
- }
3231
- return prev;
3232
- }, []);
3233
- }
3234
- /**
3235
- * Gets a list of Feature Services that are not views along with an enabled property that indicates
3236
- * if the service currently uses a spatial reference variable.
3237
- *
3238
- * @param templates A list of item templates from the solution
3239
- *
3240
- * @returns a list of feature service names and an enabled property to indicate
3241
- * if they currently use a spatial reference variable.
3242
- *
3243
- * @protected
3244
- */
3245
- _getFeatureServices(templates) {
3246
- const customizeableFeatureServices = this._getCustomizableFeatureServices(templates);
3247
- return customizeableFeatureServices.map((fs) => {
3248
- const name = fs.item.title || fs.item.name;
3249
- const wkid = getProp(fs, "properties.service.spatialReference.wkid");
3250
- return { name, enabled: wkid.toString().startsWith("{{params.wkid||") };
3251
- });
3252
- }
3253
- /**
3254
- * Capture the key item details for a given group template
3255
- *
3256
- * @param template one of the templates from the current solution
3257
- * @param templates full list of templates
3258
- *
3259
- * @returns a list of IItemShare objects
3260
- *
3261
- * @protected
3262
- */
3263
- _getItemsSharedWithThisGroup(template, templates) {
3264
- return templates.reduce((prev, cur) => {
3265
- if (cur.itemId !== template.itemId && cur.type !== "Group") {
3266
- prev.push({
3267
- id: cur.itemId,
3268
- title: cur.item.name || cur.item.title,
3269
- isShared: (cur.groups || []).indexOf(template.itemId) > -1,
3270
- shareItem: (cur.groups || []).indexOf(template.itemId) > -1,
3271
- type: cur.type,
3272
- typeKeywords: cur.item.typeKeywords
3273
- });
3274
- }
3275
- return prev;
3276
- }, []);
3277
- }
3278
- /**
3279
- * Generate storage file paths from the solution template
3280
- *
3281
- * @param solutionId the id of the current solution
3282
- * @param template the current template from the solution
3283
- * @param portal Portal where file is to be found
3284
- *
3285
- * @returns a list of resource file infos
3286
- *
3287
- * @protected
3288
- */
3289
- _getResourceFilePaths(solutionId, template, portal) {
3290
- const resourceFilePaths = generateStorageFilePaths(portal, solutionId, template.resources, SolutionTemplateFormatVersion);
3291
- return resourceFilePaths.map((fp) => {
3292
- fp.updateType = interfaces.EUpdateType.None;
3293
- return fp;
3294
- });
3295
- }
3296
- /**
3297
- * Generates a resource name from a storage file path.
3298
- *
3299
- * @param templateItemId The id of the template item whose resource this is; used as a prefix in the resource name
3300
- * @param resourcePath Resource file infos
3301
- *
3302
- * @returns The resource name to use when attaching a resource to the item.
3303
- *
3304
- * @protected
3305
- */
3306
- _getResourceStorageName(templateItemId, resourcePath) {
3307
- /* Converts
3308
- {
3309
- "url": "https://myorg.maps.arcgis.com/sharing/rest/content/items/ca924c6db7d247b9a31fa30532fb5913/resources/79036430a6274e17ae915d0278b8569c_info_metadata/metadata.xml",
3310
- "type": 2,
3311
- "folder": "",
3312
- "filename": "metadata.xml",
3313
- "updateType": 3
3314
- }
3315
- to
3316
- ca924c6db7d247b9a31fa30532fb5913_info_metadata/metadata.xml
3317
- */
3318
- let prefix = templateItemId;
3319
- switch (resourcePath.type) {
3320
- case exports.EFileType.Data:
3321
- prefix = `${prefix}_info_data`;
3322
- break;
3323
- case exports.EFileType.Info:
3324
- prefix = `${prefix}_info`;
3325
- break;
3326
- case exports.EFileType.Metadata:
3327
- prefix = `${prefix}_info_metadata`;
3328
- break;
3329
- case exports.EFileType.Resource:
3330
- break;
3331
- case exports.EFileType.Thumbnail:
3332
- prefix = `${prefix}_info_thumbnail`;
3333
- break;
3334
- }
3335
- let filenameToUse = resourcePath.filename;
3336
- if (resourcePath.type == exports.EFileType.Data && filenameToUse && !isSupportedFileType(filenameToUse)) {
3337
- filenameToUse = filenameToUse + ".zip";
3338
- prefix += "z";
3339
- }
3340
- const filename = resourcePath.folder ? resourcePath.folder + "/" + filenameToUse : filenameToUse;
3341
- return prefix + "/" + filename;
3342
- }
3343
- /**
3344
- * Extracts basic spatial reference information that is used to determine if a custom spatial reference parameter will
3345
- * be exposed while deploying this solution and if so what feature services will support it and what will the default wkid be
3346
- *
3347
- * @param services a list of objects with service name and enabled property (indicates if they currently use a spatial reference var)
3348
- * @param data the data object of a solution item
3349
- *
3350
- * @returns an object that stores if a custom spatial reference parameter is enabled/disabled,
3351
- * a list of services and if they are enabled/disabled, and the default wkid
3352
- *
3353
- * @protected
3354
- */
3355
- _getSpatialReferenceInfo(services, defaultWkid) {
3356
- const defaultServices = {};
3357
- services.forEach(service => {
3358
- defaultServices[service.name] = service.enabled;
3359
- });
3360
- return {
3361
- enabled: defaultWkid !== undefined,
3362
- services: defaultServices,
3363
- spatialReference: defaultWkid ? defaultWkid : undefined
3364
- };
3365
- }
3366
- /**
3367
- * Create and store template items for the editor.
3368
- *
3369
- * @param solutionItemId Id of the solution represented in the store
3370
- * @param templates A list of item templates from the solution
3371
- * @param authentication Credentials for fetching information to be loaded into the store
3372
- *
3373
- * @returns a promise that resolves when the templates are ready
3374
- *
3375
- * @protected
3376
- */
3377
- async _prepareSolutionItemsForEditing(solutionItemId, templates, authentication) {
3378
- const thumbnailPromises = [];
3379
- // Augment the template with paths to resources and group information, if relevant
3380
- templates.forEach((t) => {
3381
- t.resourceFilePaths = this._getResourceFilePaths(solutionItemId, t, authentication.portal);
3382
- thumbnailPromises.push(t.resourceFilePaths.length > 0 ?
3383
- getThumbnailFromStorageItem(authentication, t.resourceFilePaths) :
3384
- Promise.resolve());
3385
- t.groupDetails = t.type === "Group" ? this._getItemsSharedWithThisGroup(t, templates) : [];
3386
- });
3387
- // Augment the template with its thumbnail file
3388
- const thumbnails = await Promise.all(thumbnailPromises);
3389
- templates.forEach((t, i) => {
3390
- t.thumbnail = thumbnails[i] ? thumbnails[i] : undefined;
3391
- });
3392
- return Promise.resolve();
3393
- }
3394
- /**
3395
- * Prepares template items for sending to AGO by updating the resources held by the solution item.
3396
- *
3397
- * @param solutionItemId Id of the solution represented in the store
3398
- * @param templates A list of item templates from the solution
3399
- * @param authentication Credentials for fetching information to be loaded into the store
3400
- *
3401
- * @returns a promise that resolves when the templates are ready
3402
- *
3403
- * @protected
3404
- */
3405
- async _prepareSolutionItemsForStorage(solutionItemId, templates, authentication) {
3406
- const resourceAdds = [];
3407
- // Update the resources and remove the augmentation from a template
3408
- const pendingTasks = [];
3409
- templates.forEach((t) => {
3410
- // Run through the resourceFilePaths for the item seeking modifications to be made to the solution item's
3411
- // collection of resources; queue them for batching
3412
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
3413
- t.resourceFilePaths.forEach(async (path) => {
3414
- const storageName = this._getResourceStorageName(t.itemId, path);
3415
- switch (path.updateType) {
3416
- case interfaces.EUpdateType.Add:
3417
- const { prefix, suffix } = this._splitFilename(storageName);
3418
- t.resources.push(storageName);
3419
- resourceAdds.push({
3420
- itemId: t.itemId,
3421
- file: path.blob,
3422
- folder: prefix,
3423
- filename: suffix
3424
- });
3425
- break;
3426
- case interfaces.EUpdateType.Update:
3427
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
3428
- pendingTasks.push(new Promise(async (resolve) => {
3429
- try {
3430
- await updateItemResourceFile(solutionItemId, storageName, path.blob, authentication);
3431
- }
3432
- catch (err) {
3433
- console.log("Unable to update " + storageName + " for item " + t.itemId + ": " + JSON.stringify(err));
3434
- }
3435
- resolve();
3436
- }));
3437
- break;
3438
- case interfaces.EUpdateType.Remove:
3439
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
3440
- pendingTasks.push(new Promise(async (resolve) => {
3441
- try {
3442
- await removeItemResourceFile(solutionItemId, storageName, authentication);
3443
- t.resources = t.resources.filter((path) => path !== storageName);
3444
- }
3445
- catch (err) {
3446
- console.log("Unable to remove " + storageName + " for item " + t.itemId + ": " + JSON.stringify(err));
3447
- }
3448
- resolve();
3449
- }));
3450
- break;
3451
- }
3452
- return Promise.resolve();
3453
- });
3454
- delete t.resourceFilePaths;
3455
- delete t.thumbnail;
3456
- delete t.groupDetails;
3457
- });
3458
- // Update the resources
3459
- return Promise.all(pendingTasks)
3460
- .then(async () => {
3461
- if (resourceAdds.length > 0) {
3462
- await copyFilesToStorageItem(resourceAdds, solutionItemId, authentication);
3463
- }
3464
- return Promise.resolve();
3465
- });
3466
- }
3467
- /**
3468
- * Stores basic spatial reference information that is used to determine if a custom spatial reference parameter will
3469
- * be exposed while deploying this solution and if so what feature services will support it and what will the default wkid be
3470
- *
3471
- * @param spatialReferenceInfo The configuration settings for a custom spatial reference
3472
- * @param templates The templates in the current solution, which will be updated in place if
3473
- * `spatialReferenceInfo.enabled` is true
3474
- *
3475
- * @returns The new default wkid
3476
- *
3477
- * @protected
3478
- */
3479
- _setSpatialReferenceInfo(spatialReferenceInfo, templates) {
3480
- const customizingPrefix = "{{params.wkid||";
3481
- const customizeableFeatureServices = this._getCustomizableFeatureServices(templates);
3482
- if (spatialReferenceInfo.enabled) {
3483
- // Enable or disable this feature in each service
3484
- customizeableFeatureServices.forEach((fs) => {
3485
- const name = fs.item.title || fs.item.name;
3486
- let wkid;
3487
- if (spatialReferenceInfo.services[name]) { // enabled
3488
- wkid = `{{params.wkid||${spatialReferenceInfo.spatialReference}}}`;
3489
- setCreateProp(fs, "properties.service.spatialReference.wkid", wkid);
3490
- }
3491
- else { // disabled
3492
- wkid = getProp(fs, "properties.service.spatialReference.wkid");
3493
- // Remove customizing prefix if present
3494
- if (wkid.toString().startsWith(customizingPrefix)) {
3495
- wkid = wkid.toString().substring(customizingPrefix.length, wkid.length - 2);
3496
- setCreateProp(fs, "properties.service.spatialReference.wkid", wkid);
3497
- }
3498
- }
3499
- });
3500
- return spatialReferenceInfo.spatialReference;
3501
- }
3502
- else {
3503
- // Disable this feature in each service
3504
- customizeableFeatureServices.forEach((fs) => {
3505
- const wkid = getProp(fs, "properties.service.spatialReference.wkid");
3506
- // Remove customizing prefix if present
3507
- if (wkid.toString().startsWith(customizingPrefix)) {
3508
- setCreateProp(fs, "properties.service.spatialReference.wkid", wkid.toString().substring(customizingPrefix.length, wkid.length - 2));
3509
- }
3510
- });
3511
- return undefined;
3512
- }
3513
- }
3514
- /**
3515
- * Splits a pathed filename into a last term and a prefix; e.g., "a/b/c" returns "c" with a prefix of "a/b".
3516
- *
3517
- * @param filename Filename with optional path
3518
- *
3519
- * @returns An object consisting of a `prefix` (undefined if `filename` does not contain a path) and a `suffix`--the
3520
- * filename at the end of a path
3521
- *
3522
- * @protected
3523
- */
3524
- _splitFilename(filename) {
3525
- const filenameParts = filename.split("/");
3526
- return {
3527
- prefix: filenameParts.length > 1 ? filenameParts.slice(0, filenameParts.length - 1).join("/") : undefined,
3528
- suffix: filenameParts[filenameParts.length - 1]
3529
- };
3530
- }
3531
- }
3532
- const state = SolutionStore.Store;
3533
-
3534
- exports.getProp = getProp;
3535
- exports.state = state;
1838
+ exports.SolutionTemplateFormatVersion = SolutionTemplateFormatVersion;
1839
+ exports.jszip_min = jszip_min;