@esri/solutions-components 0.6.17 → 0.6.18

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