@esri/solution-common 4.1.2 → 5.0.0

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 (261) hide show
  1. package/dist/cjs/completeItem.d.ts +29 -29
  2. package/dist/cjs/completeItem.js +81 -81
  3. package/dist/cjs/create-hub-request-options.d.ts +29 -29
  4. package/dist/cjs/create-hub-request-options.js +63 -63
  5. package/dist/cjs/deleteHelpers/deleteEmptyGroups.d.ts +24 -24
  6. package/dist/cjs/deleteHelpers/deleteEmptyGroups.js +41 -41
  7. package/dist/cjs/deleteHelpers/deleteGroupIfEmpty.d.ts +27 -27
  8. package/dist/cjs/deleteHelpers/deleteGroupIfEmpty.js +96 -96
  9. package/dist/cjs/deleteHelpers/deleteSolutionContents.d.ts +38 -38
  10. package/dist/cjs/deleteHelpers/deleteSolutionContents.js +129 -129
  11. package/dist/cjs/deleteHelpers/deleteSolutionFolder.d.ts +29 -29
  12. package/dist/cjs/deleteHelpers/deleteSolutionFolder.js +78 -78
  13. package/dist/cjs/deleteHelpers/deleteSolutionItem.d.ts +30 -30
  14. package/dist/cjs/deleteHelpers/deleteSolutionItem.js +53 -53
  15. package/dist/cjs/deleteHelpers/index.d.ts +22 -22
  16. package/dist/cjs/deleteHelpers/index.js +25 -25
  17. package/dist/cjs/deleteHelpers/reconstructBuildOrderIds.d.ts +27 -27
  18. package/dist/cjs/deleteHelpers/reconstructBuildOrderIds.js +33 -33
  19. package/dist/cjs/deleteHelpers/removeItems.d.ts +34 -34
  20. package/dist/cjs/deleteHelpers/removeItems.js +111 -111
  21. package/dist/cjs/deleteHelpers/reportProgress.d.ts +27 -27
  22. package/dist/cjs/deleteHelpers/reportProgress.js +45 -45
  23. package/dist/cjs/deleteSolution.d.ts +55 -55
  24. package/dist/cjs/deleteSolution.js +106 -106
  25. package/dist/cjs/dependencies.d.ts +26 -26
  26. package/dist/cjs/dependencies.js +170 -170
  27. package/dist/cjs/featureServiceHelpers.d.ts +791 -791
  28. package/dist/cjs/featureServiceHelpers.js +2420 -2420
  29. package/dist/cjs/generalHelpers.d.ts +392 -385
  30. package/dist/cjs/generalHelpers.js +857 -854
  31. package/dist/cjs/generalHelpers.js.map +1 -1
  32. package/dist/cjs/get-subscription-info.d.ts +27 -27
  33. package/dist/cjs/get-subscription-info.js +38 -38
  34. package/dist/cjs/getDeletableSolutionInfo.d.ts +29 -29
  35. package/dist/cjs/getDeletableSolutionInfo.js +52 -52
  36. package/dist/cjs/getItemTypeAbbrev.d.ts +19 -19
  37. package/dist/cjs/getItemTypeAbbrev.js +184 -184
  38. package/dist/cjs/getSolutionSummary.d.ts +27 -27
  39. package/dist/cjs/getSolutionSummary.js +100 -100
  40. package/dist/cjs/index.d.ts +43 -44
  41. package/dist/cjs/index.js +46 -47
  42. package/dist/cjs/index.js.map +1 -1
  43. package/dist/cjs/interfaces.d.ts +1334 -1334
  44. package/dist/cjs/interfaces.js +74 -74
  45. package/dist/cjs/interfaces.js.map +1 -1
  46. package/dist/cjs/libConnectors.d.ts +73 -73
  47. package/dist/cjs/libConnectors.js +114 -114
  48. package/dist/cjs/migrations/apply-schema.d.ts +24 -24
  49. package/dist/cjs/migrations/apply-schema.js +35 -35
  50. package/dist/cjs/migrations/is-legacy-solution.d.ts +24 -24
  51. package/dist/cjs/migrations/is-legacy-solution.js +39 -39
  52. package/dist/cjs/migrations/upgrade-three-dot-one.d.ts +27 -27
  53. package/dist/cjs/migrations/upgrade-three-dot-one.js +48 -48
  54. package/dist/cjs/migrations/upgrade-three-dot-zero.d.ts +27 -27
  55. package/dist/cjs/migrations/upgrade-three-dot-zero.js +42 -42
  56. package/dist/cjs/migrations/upgrade-two-dot-five.d.ts +24 -24
  57. package/dist/cjs/migrations/upgrade-two-dot-five.js +72 -72
  58. package/dist/cjs/migrations/upgrade-two-dot-four.d.ts +24 -24
  59. package/dist/cjs/migrations/upgrade-two-dot-four.js +71 -71
  60. package/dist/cjs/migrations/upgrade-two-dot-one.d.ts +7 -7
  61. package/dist/cjs/migrations/upgrade-two-dot-one.js +38 -38
  62. package/dist/cjs/migrations/upgrade-two-dot-seven.d.ts +23 -23
  63. package/dist/cjs/migrations/upgrade-two-dot-seven.js +57 -57
  64. package/dist/cjs/migrations/upgrade-two-dot-six.d.ts +27 -27
  65. package/dist/cjs/migrations/upgrade-two-dot-six.js +60 -60
  66. package/dist/cjs/migrations/upgrade-two-dot-three.d.ts +23 -23
  67. package/dist/cjs/migrations/upgrade-two-dot-three.js +54 -54
  68. package/dist/cjs/migrations/upgrade-two-dot-two.d.ts +23 -23
  69. package/dist/cjs/migrations/upgrade-two-dot-two.js +57 -57
  70. package/dist/cjs/migrations/upgrade-two-dot-zero.d.ts +44 -44
  71. package/dist/cjs/migrations/upgrade-two-dot-zero.js +94 -94
  72. package/dist/cjs/migrator.d.ts +25 -25
  73. package/dist/cjs/migrator.js +76 -76
  74. package/dist/cjs/resourceHelpers.d.ts +191 -191
  75. package/dist/cjs/resourceHelpers.js +383 -390
  76. package/dist/cjs/resourceHelpers.js.map +1 -1
  77. package/dist/cjs/resources/add-resource-from-blob.d.ts +26 -26
  78. package/dist/cjs/resources/add-resource-from-blob.js +51 -51
  79. package/dist/cjs/resources/addMetadataFromBlob.d.ts +25 -25
  80. package/dist/cjs/resources/addMetadataFromBlob.js +42 -42
  81. package/dist/cjs/resources/convert-item-resource-to-storage-resource.d.ts +32 -32
  82. package/dist/cjs/resources/convert-item-resource-to-storage-resource.js +69 -69
  83. package/dist/cjs/resources/convert-storage-resource-to-item-resource.d.ts +29 -29
  84. package/dist/cjs/resources/convert-storage-resource-to-item-resource.js +69 -69
  85. package/dist/cjs/resources/copyAssociatedFiles.d.ts +67 -67
  86. package/dist/cjs/resources/copyAssociatedFiles.js +301 -301
  87. package/dist/cjs/resources/copyDataIntoItem.d.ts +33 -33
  88. package/dist/cjs/resources/copyDataIntoItem.js +61 -62
  89. package/dist/cjs/resources/copyDataIntoItem.js.map +1 -1
  90. package/dist/cjs/resources/copyMetadataIntoItem.d.ts +26 -26
  91. package/dist/cjs/resources/copyMetadataIntoItem.js +45 -45
  92. package/dist/cjs/resources/copyResourceIntoZip.d.ts +33 -33
  93. package/dist/cjs/resources/copyResourceIntoZip.js +77 -77
  94. package/dist/cjs/resources/copyZipIntoItem.d.ts +25 -25
  95. package/dist/cjs/resources/copyZipIntoItem.js +53 -53
  96. package/dist/cjs/resources/createCopyResults.d.ts +25 -25
  97. package/dist/cjs/resources/createCopyResults.js +35 -35
  98. package/dist/cjs/resources/get-blob.d.ts +26 -26
  99. package/dist/cjs/resources/get-blob.js +26 -26
  100. package/dist/cjs/resources/getItemResourcesFilesFromPaths.d.ts +24 -24
  101. package/dist/cjs/resources/getItemResourcesFilesFromPaths.js +48 -48
  102. package/dist/cjs/resources/getItemResourcesPaths.d.ts +26 -26
  103. package/dist/cjs/resources/getItemResourcesPaths.js +72 -72
  104. package/dist/cjs/resources/index.d.ts +29 -29
  105. package/dist/cjs/resources/index.js +32 -32
  106. package/dist/cjs/resources/solution-resource.d.ts +35 -35
  107. package/dist/cjs/resources/solution-resource.js +30 -30
  108. package/dist/cjs/resources/solution-resource.js.map +1 -1
  109. package/dist/cjs/resources/transform-resource-paths-to-solution-resources.d.ts +56 -56
  110. package/dist/cjs/resources/transform-resource-paths-to-solution-resources.js +145 -145
  111. package/dist/cjs/restHelpers.d.ts +586 -585
  112. package/dist/cjs/restHelpers.js +1888 -1883
  113. package/dist/cjs/restHelpers.js.map +1 -1
  114. package/dist/cjs/restHelpersGet.d.ts +288 -288
  115. package/dist/cjs/restHelpersGet.js +803 -803
  116. package/dist/cjs/sharing/index.d.ts +16 -16
  117. package/dist/cjs/sharing/index.js +19 -19
  118. package/dist/cjs/sharing/share-item-to-groups.d.ts +26 -26
  119. package/dist/cjs/sharing/share-item-to-groups.js +43 -43
  120. package/dist/cjs/templatization.d.ts +139 -139
  121. package/dist/cjs/templatization.js +313 -313
  122. package/dist/cjs/trackingHelpers.d.ts +116 -116
  123. package/dist/cjs/trackingHelpers.js +216 -216
  124. package/dist/cjs/velocityHelpers.d.ts +57 -57
  125. package/dist/cjs/velocityHelpers.js +134 -134
  126. package/dist/cjs/workforceHelpers.d.ts +115 -115
  127. package/dist/cjs/workforceHelpers.js +746 -746
  128. package/dist/cjs/workforceHelpers.js.map +1 -1
  129. package/dist/esm/completeItem.d.ts +29 -29
  130. package/dist/esm/completeItem.js +76 -76
  131. package/dist/esm/create-hub-request-options.d.ts +29 -29
  132. package/dist/esm/create-hub-request-options.js +59 -59
  133. package/dist/esm/deleteHelpers/deleteEmptyGroups.d.ts +24 -24
  134. package/dist/esm/deleteHelpers/deleteEmptyGroups.js +37 -37
  135. package/dist/esm/deleteHelpers/deleteGroupIfEmpty.d.ts +27 -27
  136. package/dist/esm/deleteHelpers/deleteGroupIfEmpty.js +91 -91
  137. package/dist/esm/deleteHelpers/deleteSolutionContents.d.ts +38 -38
  138. package/dist/esm/deleteHelpers/deleteSolutionContents.js +124 -124
  139. package/dist/esm/deleteHelpers/deleteSolutionFolder.d.ts +29 -29
  140. package/dist/esm/deleteHelpers/deleteSolutionFolder.js +73 -73
  141. package/dist/esm/deleteHelpers/deleteSolutionItem.d.ts +30 -30
  142. package/dist/esm/deleteHelpers/deleteSolutionItem.js +48 -48
  143. package/dist/esm/deleteHelpers/index.d.ts +22 -22
  144. package/dist/esm/deleteHelpers/index.js +22 -22
  145. package/dist/esm/deleteHelpers/reconstructBuildOrderIds.d.ts +27 -27
  146. package/dist/esm/deleteHelpers/reconstructBuildOrderIds.js +28 -28
  147. package/dist/esm/deleteHelpers/removeItems.d.ts +34 -34
  148. package/dist/esm/deleteHelpers/removeItems.js +106 -106
  149. package/dist/esm/deleteHelpers/reportProgress.d.ts +27 -27
  150. package/dist/esm/deleteHelpers/reportProgress.js +41 -41
  151. package/dist/esm/deleteSolution.d.ts +55 -55
  152. package/dist/esm/deleteSolution.js +100 -100
  153. package/dist/esm/dependencies.d.ts +26 -26
  154. package/dist/esm/dependencies.js +166 -166
  155. package/dist/esm/featureServiceHelpers.d.ts +791 -791
  156. package/dist/esm/featureServiceHelpers.js +2336 -2336
  157. package/dist/esm/generalHelpers.d.ts +392 -385
  158. package/dist/esm/generalHelpers.js +810 -808
  159. package/dist/esm/generalHelpers.js.map +1 -1
  160. package/dist/esm/get-subscription-info.d.ts +27 -27
  161. package/dist/esm/get-subscription-info.js +34 -34
  162. package/dist/esm/getDeletableSolutionInfo.d.ts +29 -29
  163. package/dist/esm/getDeletableSolutionInfo.js +47 -47
  164. package/dist/esm/getItemTypeAbbrev.d.ts +19 -19
  165. package/dist/esm/getItemTypeAbbrev.js +180 -180
  166. package/dist/esm/getSolutionSummary.d.ts +27 -27
  167. package/dist/esm/getSolutionSummary.js +95 -95
  168. package/dist/esm/index.d.ts +43 -44
  169. package/dist/esm/index.js +43 -44
  170. package/dist/esm/index.js.map +1 -1
  171. package/dist/esm/interfaces.d.ts +1334 -1334
  172. package/dist/esm/interfaces.js +70 -70
  173. package/dist/esm/libConnectors.d.ts +73 -73
  174. package/dist/esm/libConnectors.js +104 -104
  175. package/dist/esm/migrations/apply-schema.d.ts +24 -24
  176. package/dist/esm/migrations/apply-schema.js +31 -31
  177. package/dist/esm/migrations/is-legacy-solution.d.ts +24 -24
  178. package/dist/esm/migrations/is-legacy-solution.js +35 -35
  179. package/dist/esm/migrations/upgrade-three-dot-one.d.ts +27 -27
  180. package/dist/esm/migrations/upgrade-three-dot-one.js +44 -44
  181. package/dist/esm/migrations/upgrade-three-dot-zero.d.ts +27 -27
  182. package/dist/esm/migrations/upgrade-three-dot-zero.js +38 -38
  183. package/dist/esm/migrations/upgrade-two-dot-five.d.ts +24 -24
  184. package/dist/esm/migrations/upgrade-two-dot-five.js +68 -68
  185. package/dist/esm/migrations/upgrade-two-dot-four.d.ts +24 -24
  186. package/dist/esm/migrations/upgrade-two-dot-four.js +67 -67
  187. package/dist/esm/migrations/upgrade-two-dot-one.d.ts +7 -7
  188. package/dist/esm/migrations/upgrade-two-dot-one.js +34 -34
  189. package/dist/esm/migrations/upgrade-two-dot-seven.d.ts +23 -23
  190. package/dist/esm/migrations/upgrade-two-dot-seven.js +53 -53
  191. package/dist/esm/migrations/upgrade-two-dot-six.d.ts +27 -27
  192. package/dist/esm/migrations/upgrade-two-dot-six.js +56 -56
  193. package/dist/esm/migrations/upgrade-two-dot-three.d.ts +23 -23
  194. package/dist/esm/migrations/upgrade-two-dot-three.js +50 -50
  195. package/dist/esm/migrations/upgrade-two-dot-two.d.ts +23 -23
  196. package/dist/esm/migrations/upgrade-two-dot-two.js +53 -53
  197. package/dist/esm/migrations/upgrade-two-dot-zero.d.ts +44 -44
  198. package/dist/esm/migrations/upgrade-two-dot-zero.js +87 -87
  199. package/dist/esm/migrator.d.ts +25 -25
  200. package/dist/esm/migrator.js +72 -72
  201. package/dist/esm/resourceHelpers.d.ts +191 -191
  202. package/dist/esm/resourceHelpers.js +364 -371
  203. package/dist/esm/resourceHelpers.js.map +1 -1
  204. package/dist/esm/resources/add-resource-from-blob.d.ts +26 -26
  205. package/dist/esm/resources/add-resource-from-blob.js +47 -47
  206. package/dist/esm/resources/addMetadataFromBlob.d.ts +25 -25
  207. package/dist/esm/resources/addMetadataFromBlob.js +38 -38
  208. package/dist/esm/resources/convert-item-resource-to-storage-resource.d.ts +32 -32
  209. package/dist/esm/resources/convert-item-resource-to-storage-resource.js +65 -65
  210. package/dist/esm/resources/convert-storage-resource-to-item-resource.d.ts +29 -29
  211. package/dist/esm/resources/convert-storage-resource-to-item-resource.js +65 -65
  212. package/dist/esm/resources/copyAssociatedFiles.d.ts +67 -67
  213. package/dist/esm/resources/copyAssociatedFiles.js +293 -293
  214. package/dist/esm/resources/copyDataIntoItem.d.ts +33 -33
  215. package/dist/esm/resources/copyDataIntoItem.js +56 -57
  216. package/dist/esm/resources/copyDataIntoItem.js.map +1 -1
  217. package/dist/esm/resources/copyMetadataIntoItem.d.ts +26 -26
  218. package/dist/esm/resources/copyMetadataIntoItem.js +41 -41
  219. package/dist/esm/resources/copyResourceIntoZip.d.ts +33 -33
  220. package/dist/esm/resources/copyResourceIntoZip.js +72 -72
  221. package/dist/esm/resources/copyZipIntoItem.d.ts +25 -25
  222. package/dist/esm/resources/copyZipIntoItem.js +49 -49
  223. package/dist/esm/resources/createCopyResults.d.ts +25 -25
  224. package/dist/esm/resources/createCopyResults.js +31 -31
  225. package/dist/esm/resources/get-blob.d.ts +26 -26
  226. package/dist/esm/resources/get-blob.js +22 -22
  227. package/dist/esm/resources/getItemResourcesFilesFromPaths.d.ts +24 -24
  228. package/dist/esm/resources/getItemResourcesFilesFromPaths.js +44 -44
  229. package/dist/esm/resources/getItemResourcesPaths.d.ts +26 -26
  230. package/dist/esm/resources/getItemResourcesPaths.js +68 -68
  231. package/dist/esm/resources/index.d.ts +29 -29
  232. package/dist/esm/resources/index.js +29 -29
  233. package/dist/esm/resources/solution-resource.d.ts +35 -35
  234. package/dist/esm/resources/solution-resource.js +27 -27
  235. package/dist/esm/resources/transform-resource-paths-to-solution-resources.d.ts +56 -56
  236. package/dist/esm/resources/transform-resource-paths-to-solution-resources.js +137 -137
  237. package/dist/esm/restHelpers.d.ts +586 -585
  238. package/dist/esm/restHelpers.js +1827 -1823
  239. package/dist/esm/restHelpers.js.map +1 -1
  240. package/dist/esm/restHelpersGet.d.ts +288 -288
  241. package/dist/esm/restHelpersGet.js +763 -763
  242. package/dist/esm/sharing/index.d.ts +16 -16
  243. package/dist/esm/sharing/index.js +16 -16
  244. package/dist/esm/sharing/share-item-to-groups.d.ts +26 -26
  245. package/dist/esm/sharing/share-item-to-groups.js +39 -39
  246. package/dist/esm/templatization.d.ts +139 -139
  247. package/dist/esm/templatization.js +293 -293
  248. package/dist/esm/trackingHelpers.d.ts +116 -116
  249. package/dist/esm/trackingHelpers.js +204 -204
  250. package/dist/esm/velocityHelpers.d.ts +57 -57
  251. package/dist/esm/velocityHelpers.js +128 -128
  252. package/dist/esm/workforceHelpers.d.ts +115 -115
  253. package/dist/esm/workforceHelpers.js +717 -717
  254. package/dist/esm/workforceHelpers.js.map +1 -1
  255. package/package.json +2 -2
  256. package/dist/cjs/polyfills.d.ts +0 -40
  257. package/dist/cjs/polyfills.js +0 -98
  258. package/dist/cjs/polyfills.js.map +0 -1
  259. package/dist/esm/polyfills.d.ts +0 -40
  260. package/dist/esm/polyfills.js +0 -93
  261. package/dist/esm/polyfills.js.map +0 -1
@@ -1,372 +1,365 @@
1
- /** @license
2
- * Copyright 2018 Esri
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- /**
17
- * Provides common functions involving the management of item and group resources.
18
- *
19
- * @module resourceHelpers
20
- *
21
- * How it works
22
- *
23
- * An item may have resources that are listed as a set of filenames and/or folder/filename combinations. It may have
24
- * a thumbnail, listed in its item info as a filename or folder/filename combination. It may have metadata, which is
25
- * not listed, but has a distinct URL. A group may have a thumbnail, but not the others.
26
- *
27
- * For storing these files in a common storage item, a new folder and filename combination is created for each. The
28
- * filename is kept as-is. The folder consists of the source item's id and an optional suffix. For thumbnails, the
29
- * suffix is "_info_thumbnail"; for metadata, the suffix is "_info_metadata"; for resources, the suffix is "_" plus
30
- * the resource's folder's name; if the resource doesn't have a folder, there is no suffix.
31
- *
32
- * Note that "thumbnail" is included in an item's thumbnail property like a folder (e.g., "thumbnail/thumbnail.png"),
33
- * and the item's thumbnail is accessed using a path such as "%lt;itemId>/info/thumbnail/thumbnail.png". Groups,
34
- * on the other hand, have a property with a simple name (e.g., "thumbnail.png") and it is accessed using a path
35
- * such as "%lt;groupId>/info/thumbnail.png".
36
- *
37
- * For copying these files from the common storage item to another item, one converts the unique names back into the
38
- * original names (or the special cases for thumbnails and metadata).
39
- *
40
- * Routines are provided to
41
- * 1. create full URLs to resources, thumbnails, and metadata.
42
- * 2. create a folder and filename combination that uniquely identifies these files for
43
- * storing them in a single, shared storage item
44
- * 3. copy a set of resources, thumbnails, and metadata for an item to a storage item
45
- * 4. copy a file by URL to an item using specified folder and filename
46
- * 5. undo the unique folder and filename into the original folder and filename
47
- */
48
- import { EFileType } from "./interfaces";
49
- import { new_File } from "./polyfills";
50
- import { removeItemResource, updateGroup, updateItem, updateItemResource } from "@esri/arcgis-rest-portal";
51
- import { appendQueryParam, checkUrlPathTermination } from "./generalHelpers";
52
- import { convertItemResourceToStorageResource } from "./resources/convert-item-resource-to-storage-resource";
53
- import { convertStorageResourceToItemResource } from "./resources/convert-storage-resource-to-item-resource";
54
- import { getThumbnailFile } from "./restHelpersGet";
55
- import { copyAssociatedFilesByType, copyFilesAsResources } from "./resources/copyAssociatedFiles";
56
- // ------------------------------------------------------------------------------------------------------------------ //
57
- export function addThumbnailFromBlob(blob, itemId, authentication, isGroup = false) {
58
- const updateOptions = {
59
- params: {
60
- // Pass image in directly because item object is serialized, which discards a blob
61
- thumbnail: blob
62
- },
63
- authentication: authentication
64
- };
65
- updateOptions[isGroup ? "group" : "item"] = {
66
- id: itemId
67
- };
68
- return isGroup ? updateGroup(updateOptions) : updateItem(updateOptions);
69
- }
70
- export function convertBlobToSupportableResource(blob, filename = "") {
71
- const originalFilename = blob.name || filename;
72
- let filenameToUse = originalFilename;
73
- if (filenameToUse && !isSupportedFileType(filenameToUse)) {
74
- filenameToUse = filenameToUse + ".zip";
75
- }
76
- return {
77
- blob: new_File([blob], filenameToUse, { type: blob.type }),
78
- filename: originalFilename,
79
- mimeType: blob.type
80
- };
81
- }
82
- /**
83
- * Copies the files described by a list of full URLs and folder/filename combinations for
84
- * the resources and metadata of an item or group to an item.
85
- *
86
- * @param storageAuthentication Credentials for the request to the storage
87
- * @param filePaths List of item files' URLs and folder/filenames for storing the files
88
- * @param sourceItemId Id of item supplying resource/metadata
89
- * @param destinationFolderId Id of folder
90
- * @param destinationItemId Id of item to receive copy of resource/metadata
91
- * @param destinationAuthentication Credentials for the request to the destination
92
- * @param template Description of item that will receive files
93
- * @returns A promise which resolves to a boolean indicating if the copies were successful
94
- */
95
- export function copyFilesFromStorageItem(storageAuthentication, filePaths, sourceItemId, destinationFolderId, destinationItemId, destinationAuthentication, template = {}) {
96
- // TODO: This is only used in deployer, so move there
97
- // changed to allow the template to be passed in
98
- // because Hub templates need to swap out the templateId
99
- // in the resource filename
100
- const mimeTypes = template.properties || null;
101
- // remove the template.itemId from the fileName in the filePaths
102
- /* istanbul ignore else */
103
- if (template.itemId) {
104
- filePaths = filePaths.map(fp => {
105
- /* istanbul ignore else */
106
- if (fp.filename.indexOf(template.itemId) === 0 && fp.folder === "") {
107
- fp.filename = fp.filename.replace(`${template.itemId}-`, "");
108
- }
109
- return fp;
110
- });
111
- }
112
- return new Promise((resolve, reject) => {
113
- const fileInfos = filePaths.map(path => {
114
- return {
115
- folder: path.type === EFileType.Data ? destinationFolderId : path.folder,
116
- filename: path.filename,
117
- type: path.type,
118
- mimeType: mimeTypes ? mimeTypes[path.filename] : "",
119
- url: path.url
120
- };
121
- });
122
- void copyAssociatedFilesByType(fileInfos, storageAuthentication, sourceItemId, destinationItemId, destinationAuthentication, template).then((results) => {
123
- const allOK = results
124
- // Filter out metadata
125
- .filter((result) => result.filename !== "metadata.xml")
126
- // Extract success
127
- .map((result) => result.fetchedFromSource && result.copiedToDestination)
128
- // Boil it down to a single result
129
- .reduce((success, currentValue) => success && currentValue, true);
130
- if (allOK) {
131
- resolve(true);
132
- }
133
- else {
134
- reject();
135
- }
136
- });
137
- });
138
- }
139
- /**
140
- * Copies the files for storing the resources, metadata, and thumbnail of an item or group to a storage item
141
- * with a specified path.
142
- *
143
- * @param files List of item files and paths for storing the files
144
- * @param storageItemId Id of item to receive copy of resource/metadata
145
- * @param storageAuthentication Credentials for the request to the storage
146
- * @returns A promise which resolves to a list of the filenames under which the resource/metadata are stored
147
- */
148
- export function copyFilesToStorageItem(files, storageItemId, storageAuthentication) {
149
- return new Promise(resolve => {
150
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
151
- void copyFilesAsResources(files, storageItemId, storageAuthentication).then((results) => {
152
- resolve(results
153
- // Filter out failures
154
- .filter((result) => result.fetchedFromSource && result.copiedToDestination)
155
- // Return folder and filename in storage item's resources
156
- .map((result) => result.folder + "/" + result.filename));
157
- });
158
- });
159
- }
160
- /**
161
- * Generates a folder and filename for storing a copy of an item's metadata in a storage item.
162
- *
163
- * @param itemId Id of item
164
- * @returns Folder and filename for storage; folder is the itemID suffixed with "_info_metadata"
165
- * @see convertStorageResourceToItemResource
166
- */
167
- export function generateMetadataStorageFilename(itemId) {
168
- return {
169
- folder: itemId + "_info_metadata",
170
- filename: "metadata.xml"
171
- };
172
- }
173
- /**
174
- * Generates a list of full URLs and storage folder/filename combinations for storing the resources, metadata,
175
- * and thumbnail of an item.
176
- *
177
- * @param portalSharingUrl Server/sharing
178
- * @param itemId Id of item
179
- * @param thumbnailUrlPart Partial path to the thumbnail held in an item's JSON
180
- * @param resourceFilenames List of resource filenames for an item, e.g., ["file1", "myFolder/file2"]
181
- * @param isGroup Boolean to indicate if the files are associated with a group or item
182
- * @param storageVersion Version of the Solution template
183
- * @returns List of item files' URLs and folder/filenames for storing the files
184
- */
185
- export function generateSourceFilePaths(portalSharingUrl, itemId, thumbnailUrlPart, resourceFilenames, isGroup = false, storageVersion = 0) {
186
- const filePaths = resourceFilenames.map(resourceFilename => {
187
- return {
188
- itemId,
189
- url: generateSourceResourceUrl(portalSharingUrl, itemId, resourceFilename),
190
- ...convertItemResourceToStorageResource(itemId, resourceFilename, storageVersion)
191
- };
192
- });
193
- filePaths.push({
194
- itemId,
195
- url: generateSourceMetadataUrl(portalSharingUrl, itemId, isGroup),
196
- ...generateMetadataStorageFilename(itemId)
197
- });
198
- /* istanbul ignore else */
199
- if (thumbnailUrlPart) {
200
- const path = {
201
- itemId,
202
- url: appendQueryParam(generateSourceThumbnailUrl(portalSharingUrl, itemId, thumbnailUrlPart, isGroup), "w=400"),
203
- ...generateThumbnailStorageFilename(itemId, thumbnailUrlPart)
204
- };
205
- filePaths.push(path);
206
- }
207
- return filePaths;
208
- }
209
- /**
210
- * Generates the URL for reading an item's metadata.
211
- *
212
- * @param sourcePortalSharingUrl Server/sharing
213
- * @param itemId Id of item
214
- * @param isGroup Boolean to indicate if the files are associated with a group or item
215
- * @returns URL string
216
- */
217
- export function generateSourceMetadataUrl(sourcePortalSharingUrl, itemId, isGroup = false) {
218
- return (checkUrlPathTermination(sourcePortalSharingUrl) +
219
- (isGroup ? "community/groups/" : "content/items/") +
220
- itemId +
221
- "/info/metadata/metadata.xml");
222
- }
223
- /**
224
- * Generates the URL for reading an item's resource given the filename of the resource.
225
- *
226
- * @param sourcePortalSharingUrl Server/sharing
227
- * @param itemId Id of item
228
- * @param sourceResourceFilename Either filename or folder/filename to resource
229
- * @returns URL string
230
- */
231
- export function generateSourceResourceUrl(sourcePortalSharingUrl, itemId, sourceResourceFilename) {
232
- return (checkUrlPathTermination(sourcePortalSharingUrl) +
233
- "content/items/" +
234
- itemId +
235
- "/resources/" +
236
- sourceResourceFilename);
237
- }
238
- /**
239
- * Generates the URL for reading an item's thumbnail.
240
- *
241
- * @param sourcePortalSharingUrl Server/sharing
242
- * @param itemId Id of item
243
- * @param thumbnailUrlPart Partial path to the thumbnail held in an item's JSON
244
- * @param isGroup Boolean to indicate if the files are associated with a group or item
245
- * @returns URL string
246
- */
247
- export function generateSourceThumbnailUrl(sourcePortalSharingUrl, itemId, thumbnailUrlPart, isGroup = false) {
248
- return (checkUrlPathTermination(sourcePortalSharingUrl) +
249
- (isGroup ? "community/groups/" : "content/items/") +
250
- itemId +
251
- "/info/" +
252
- thumbnailUrlPart);
253
- }
254
- /**
255
- * Generates a list of full URLs and folder/filename combinations used to store the resources, metadata,
256
- * and thumbnail of an item.
257
- *
258
- * @param portalSharingUrl Server/sharing
259
- * @param storageItemId Id of storage item
260
- * @param resourceFilenames List of resource filenames for an item, e.g., ["file1", "myFolder/file2"]
261
- * @param storageVersion Version of the Solution template
262
- * @returns List of item files' URLs and folder/filenames for storing the files
263
- */
264
- export function generateStorageFilePaths(portalSharingUrl, storageItemId, resourceFilenames = [], storageVersion = 0) {
265
- return resourceFilenames.map(resourceFilename => {
266
- return {
267
- url: generateSourceResourceUrl(portalSharingUrl, storageItemId, resourceFilename),
268
- ...convertStorageResourceToItemResource(resourceFilename, storageVersion)
269
- };
270
- });
271
- }
272
- /**
273
- * Generates a folder and filename for storing a copy of an item's thumbnail in a storage item.
274
- *
275
- * @param itemId Id of item
276
- * @param thumbnailUrlPart Partial path to the thumbnail held in an item's JSON; can also be a filename
277
- * @returns Folder and filename for storage; folder is the itemID suffixed with "_info_thumbnail";
278
- * file is URI-encoded thumbnailUrlPart
279
- * @see convertStorageResourceToItemResource
280
- */
281
- export function generateThumbnailStorageFilename(itemId, thumbnailurl) {
282
- const folder = itemId + "_info_thumbnail";
283
- const thumbnailUrlParts = thumbnailurl.split("/");
284
- const filename = thumbnailUrlParts.length === 1
285
- ? thumbnailUrlParts[0]
286
- : thumbnailUrlParts[1];
287
- return { folder, filename };
288
- }
289
- export function isSupportedFileType(filename) {
290
- // Supported file formats are: .json, .xml, .txt, .png, .pbf, .zip, .jpeg, .jpg, .gif, .bmp, .gz, .svg,
291
- // .svgz, .geodatabase (https://developers.arcgis.com/rest/users-groups-and-items/add-resources.htm)
292
- const filenameExtension = filename.match(/\.([a-z]+)$/i);
293
- const supportedExtensions = "|.json|.xml|.txt|.png|.pbf|.zip|.jpeg|.jpg|.gif|.bmp|.gz|.svg|.svgz|.geodatabase|";
294
- return (!!filenameExtension &&
295
- supportedExtensions.indexOf("|" + filenameExtension[0] + "|") >= 0);
296
- }
297
- /**
298
- * Gets the thumbnail of an item or group.
299
- *
300
- * @param authentication Credentials for the request to the storage
301
- * @param filePaths List of item files' URLs and folder/filenames for storing the files
302
- * @returns A promise which resolves to a boolean indicating if the copies were successful
303
- */
304
- export function getThumbnailFromStorageItem(authentication, filePaths) {
305
- let thumbnailUrl;
306
- let thumbnailFilename;
307
- filePaths.forEach(path => {
308
- if (path.type === EFileType.Thumbnail) {
309
- thumbnailUrl = path.url;
310
- thumbnailFilename = path.filename;
311
- }
312
- });
313
- if (!thumbnailUrl) {
314
- return Promise.resolve(null);
315
- }
316
- return getThumbnailFile(thumbnailUrl, thumbnailFilename, authentication);
317
- }
318
- /**
319
- * Removes the item's resource that matches the filename with new content
320
- *
321
- * @param itemId Id of the item to remove
322
- * @param filename Name of the resource file to remove
323
- * @param authentication Credentials for the request to the storage
324
- * @returns A promise which resolves with a success true/false response
325
- */
326
- export function removeItemResourceFile(itemId, filename, authentication) {
327
- return removeItemResource({
328
- id: itemId,
329
- resource: filename,
330
- authentication: authentication
331
- });
332
- }
333
- /**
334
- * Updates the item's resource that matches the filename with new content
335
- *
336
- * @param itemId Id of the item to update
337
- * @param filename Name of the resource file to update; prefix optional (e.g., a/b/file.txt)
338
- * @param resource The new content to update the resource with
339
- * @param authentication Credentials for the request to the storage
340
- * @returns A promise which resolves with a success true/false response
341
- */
342
- export function updateItemResourceFile(itemId, filename, resource, authentication) {
343
- // Prefix has to be specified separately
344
- const prefixedFilenameParts = filename.split("/");
345
- const prefix = prefixedFilenameParts.length > 1 ? prefixedFilenameParts.slice(0, prefixedFilenameParts.length - 1).join("/") : undefined;
346
- const suffix = prefixedFilenameParts[prefixedFilenameParts.length - 1];
347
- return updateItemResource({
348
- id: itemId,
349
- prefix: prefix,
350
- name: suffix,
351
- resource,
352
- authentication: authentication
353
- });
354
- }
355
- /**
356
- * Updates the item's resource that matches the filename with new content
357
- *
358
- * @param itemId Id of the item to update
359
- * @param filename Name of the resource file to update
360
- * @param content The new content to update the resource with
361
- * @param authentication Credentials for the request to the storage
362
- * @returns A promise which resolves with a success true/false response
363
- */
364
- export function updateItemResourceText(itemId, filename, content, authentication) {
365
- return updateItemResource({
366
- id: itemId,
367
- name: filename,
368
- content: content,
369
- authentication: authentication
370
- });
371
- }
1
+ /** @license
2
+ * Copyright 2018 Esri
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Provides common functions involving the management of item and group resources.
18
+ *
19
+ * @module resourceHelpers
20
+ *
21
+ * How it works
22
+ *
23
+ * An item may have resources that are listed as a set of filenames and/or folder/filename combinations. It may have
24
+ * a thumbnail, listed in its item info as a filename or folder/filename combination. It may have metadata, which is
25
+ * not listed, but has a distinct URL. A group may have a thumbnail, but not the others.
26
+ *
27
+ * For storing these files in a common storage item, a new folder and filename combination is created for each. The
28
+ * filename is kept as-is. The folder consists of the source item's id and an optional suffix. For thumbnails, the
29
+ * suffix is "_info_thumbnail"; for metadata, the suffix is "_info_metadata"; for resources, the suffix is "_" plus
30
+ * the resource's folder's name; if the resource doesn't have a folder, there is no suffix.
31
+ *
32
+ * Note that "thumbnail" is included in an item's thumbnail property like a folder (e.g., "thumbnail/thumbnail.png"),
33
+ * and the item's thumbnail is accessed using a path such as "%lt;itemId>/info/thumbnail/thumbnail.png". Groups,
34
+ * on the other hand, have a property with a simple name (e.g., "thumbnail.png") and it is accessed using a path
35
+ * such as "%lt;groupId>/info/thumbnail.png".
36
+ *
37
+ * For copying these files from the common storage item to another item, one converts the unique names back into the
38
+ * original names (or the special cases for thumbnails and metadata).
39
+ *
40
+ * Routines are provided to
41
+ * 1. create full URLs to resources, thumbnails, and metadata.
42
+ * 2. create a folder and filename combination that uniquely identifies these files for
43
+ * storing them in a single, shared storage item
44
+ * 3. copy a set of resources, thumbnails, and metadata for an item to a storage item
45
+ * 4. copy a file by URL to an item using specified folder and filename
46
+ * 5. undo the unique folder and filename into the original folder and filename
47
+ */
48
+ import { EFileType } from "./interfaces";
49
+ import { removeItemResource, updateGroup, updateItem, updateItemResource } from "@esri/arcgis-rest-portal";
50
+ import { appendQueryParam, checkUrlPathTermination } from "./generalHelpers";
51
+ import { convertItemResourceToStorageResource } from "./resources/convert-item-resource-to-storage-resource";
52
+ import { convertStorageResourceToItemResource } from "./resources/convert-storage-resource-to-item-resource";
53
+ import { getThumbnailFile } from "./restHelpersGet";
54
+ import { copyAssociatedFilesByType, copyFilesAsResources } from "./resources/copyAssociatedFiles";
55
+ // ------------------------------------------------------------------------------------------------------------------ //
56
+ export function addThumbnailFromBlob(blob, itemId, authentication, isGroup = false) {
57
+ const updateOptions = {
58
+ params: {
59
+ // Pass image in directly because item object is serialized, which discards a blob
60
+ thumbnail: blob
61
+ },
62
+ authentication: authentication
63
+ };
64
+ updateOptions[isGroup ? "group" : "item"] = {
65
+ id: itemId
66
+ };
67
+ return isGroup ? updateGroup(updateOptions) : updateItem(updateOptions);
68
+ }
69
+ export function convertBlobToSupportableResource(blob, filename = "") {
70
+ const originalFilename = blob.name || filename;
71
+ let filenameToUse = originalFilename;
72
+ if (filenameToUse && !isSupportedFileType(filenameToUse)) {
73
+ filenameToUse = filenameToUse + ".zip";
74
+ }
75
+ return {
76
+ blob: new File([blob], filenameToUse, { type: blob.type }),
77
+ filename: originalFilename,
78
+ mimeType: blob.type
79
+ };
80
+ }
81
+ /**
82
+ * Copies the files described by a list of full URLs and folder/filename combinations for
83
+ * the resources and metadata of an item or group to an item.
84
+ *
85
+ * @param storageAuthentication Credentials for the request to the storage
86
+ * @param filePaths List of item files' URLs and folder/filenames for storing the files
87
+ * @param sourceItemId Id of item supplying resource/metadata
88
+ * @param destinationFolderId Id of folder
89
+ * @param destinationItemId Id of item to receive copy of resource/metadata
90
+ * @param destinationAuthentication Credentials for the request to the destination
91
+ * @param template Description of item that will receive files
92
+ * @returns A promise which resolves to a boolean indicating if the copies were successful
93
+ */
94
+ export function copyFilesFromStorageItem(storageAuthentication, filePaths, sourceItemId, destinationFolderId, destinationItemId, destinationAuthentication, template = {}) {
95
+ // TODO: This is only used in deployer, so move there
96
+ // changed to allow the template to be passed in
97
+ // because Hub templates need to swap out the templateId
98
+ // in the resource filename
99
+ const mimeTypes = template.properties || null;
100
+ // remove the template.itemId from the fileName in the filePaths
101
+ /* istanbul ignore else */
102
+ if (template.itemId) {
103
+ filePaths = filePaths.map(fp => {
104
+ /* istanbul ignore else */
105
+ if (fp.filename.indexOf(template.itemId) === 0 && fp.folder === "") {
106
+ fp.filename = fp.filename.replace(`${template.itemId}-`, "");
107
+ }
108
+ return fp;
109
+ });
110
+ }
111
+ return new Promise((resolve, reject) => {
112
+ const fileInfos = filePaths.map(path => {
113
+ return {
114
+ folder: path.type === EFileType.Data ? destinationFolderId : path.folder,
115
+ filename: path.filename,
116
+ type: path.type,
117
+ mimeType: mimeTypes ? mimeTypes[path.filename] : "",
118
+ url: path.url
119
+ };
120
+ });
121
+ void copyAssociatedFilesByType(fileInfos, storageAuthentication, sourceItemId, destinationItemId, destinationAuthentication, template).then((results) => {
122
+ const allOK = results
123
+ // Filter out metadata
124
+ .filter((result) => result.filename !== "metadata.xml")
125
+ // Extract success
126
+ .map((result) => result.fetchedFromSource && result.copiedToDestination)
127
+ // Boil it down to a single result
128
+ .reduce((success, currentValue) => success && currentValue, true);
129
+ if (allOK) {
130
+ resolve(true);
131
+ }
132
+ else {
133
+ reject();
134
+ }
135
+ });
136
+ });
137
+ }
138
+ /**
139
+ * Copies the files for storing the resources, metadata, and thumbnail of an item or group to a storage item
140
+ * with a specified path.
141
+ *
142
+ * @param files List of item files and paths for storing the files
143
+ * @param storageItemId Id of item to receive copy of resource/metadata
144
+ * @param storageAuthentication Credentials for the request to the storage
145
+ * @returns A promise which resolves to a list of the filenames under which the resource/metadata are stored
146
+ */
147
+ export function copyFilesToStorageItem(files, storageItemId, storageAuthentication) {
148
+ return new Promise(resolve => {
149
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
150
+ void copyFilesAsResources(files, storageItemId, storageAuthentication).then((results) => {
151
+ resolve(results
152
+ // Filter out failures
153
+ .filter((result) => result.fetchedFromSource && result.copiedToDestination)
154
+ // Return folder and filename in storage item's resources
155
+ .map((result) => result.folder + "/" + result.filename));
156
+ });
157
+ });
158
+ }
159
+ /**
160
+ * Generates a folder and filename for storing a copy of an item's metadata in a storage item.
161
+ *
162
+ * @param itemId Id of item
163
+ * @returns Folder and filename for storage; folder is the itemID suffixed with "_info_metadata"
164
+ * @see convertStorageResourceToItemResource
165
+ */
166
+ export function generateMetadataStorageFilename(itemId) {
167
+ return {
168
+ folder: itemId + "_info_metadata",
169
+ filename: "metadata.xml"
170
+ };
171
+ }
172
+ /**
173
+ * Generates a list of full URLs and storage folder/filename combinations for storing the resources, metadata,
174
+ * and thumbnail of an item.
175
+ *
176
+ * @param portalSharingUrl Server/sharing
177
+ * @param itemId Id of item
178
+ * @param thumbnailUrlPart Partial path to the thumbnail held in an item's JSON
179
+ * @param resourceFilenames List of resource filenames for an item, e.g., ["file1", "myFolder/file2"]
180
+ * @param isGroup Boolean to indicate if the files are associated with a group or item
181
+ * @param storageVersion Version of the Solution template
182
+ * @returns List of item files' URLs and folder/filenames for storing the files
183
+ */
184
+ export function generateSourceFilePaths(portalSharingUrl, itemId, thumbnailUrlPart, resourceFilenames, isGroup = false, storageVersion = 0) {
185
+ const filePaths = resourceFilenames.map(resourceFilename => {
186
+ return {
187
+ itemId,
188
+ url: generateSourceResourceUrl(portalSharingUrl, itemId, resourceFilename),
189
+ ...convertItemResourceToStorageResource(itemId, resourceFilename, storageVersion)
190
+ };
191
+ });
192
+ filePaths.push({
193
+ itemId,
194
+ url: generateSourceMetadataUrl(portalSharingUrl, itemId, isGroup),
195
+ ...generateMetadataStorageFilename(itemId)
196
+ });
197
+ /* istanbul ignore else */
198
+ if (thumbnailUrlPart) {
199
+ filePaths.push(generateSourceThumbnailPath(portalSharingUrl, itemId, thumbnailUrlPart, isGroup));
200
+ }
201
+ return filePaths;
202
+ }
203
+ /**
204
+ * Generates the full URL and storage folder/filename for storing an item's thumbnail.
205
+ *
206
+ * @param portalSharingUrl Server/sharing
207
+ * @param itemId Id of item
208
+ * @param thumbnailUrlPart Partial path to the thumbnail held in an item's JSON
209
+ * @param isGroup Boolean to indicate if the files are associated with a group or item
210
+ * @returns URL and folder/filename for storing the thumbnail
211
+ */
212
+ export function generateSourceThumbnailPath(portalSharingUrl, itemId, thumbnailUrlPart, isGroup = false) {
213
+ return {
214
+ itemId,
215
+ url: appendQueryParam(generateSourceThumbnailUrl(portalSharingUrl, itemId, thumbnailUrlPart, isGroup), "w=400"),
216
+ ...generateThumbnailStorageFilename(itemId, thumbnailUrlPart)
217
+ };
218
+ }
219
+ /**
220
+ * Generates the URL for reading an item's metadata.
221
+ *
222
+ * @param sourcePortalSharingUrl Server/sharing
223
+ * @param itemId Id of item
224
+ * @param isGroup Boolean to indicate if the files are associated with a group or item
225
+ * @returns URL string
226
+ */
227
+ export function generateSourceMetadataUrl(sourcePortalSharingUrl, itemId, isGroup = false) {
228
+ return (checkUrlPathTermination(sourcePortalSharingUrl) +
229
+ (isGroup ? "community/groups/" : "content/items/") +
230
+ itemId +
231
+ "/info/metadata/metadata.xml");
232
+ }
233
+ /**
234
+ * Generates the URL for reading an item's resource given the filename of the resource.
235
+ *
236
+ * @param sourcePortalSharingUrl Server/sharing
237
+ * @param itemId Id of item
238
+ * @param sourceResourceFilename Either filename or folder/filename to resource
239
+ * @returns URL string
240
+ */
241
+ export function generateSourceResourceUrl(sourcePortalSharingUrl, itemId, sourceResourceFilename) {
242
+ return (checkUrlPathTermination(sourcePortalSharingUrl) +
243
+ "content/items/" +
244
+ itemId +
245
+ "/resources/" +
246
+ sourceResourceFilename);
247
+ }
248
+ /**
249
+ * Generates the URL for reading an item's thumbnail.
250
+ *
251
+ * @param sourcePortalSharingUrl Server/sharing
252
+ * @param itemId Id of item
253
+ * @param thumbnailUrlPart Partial path to the thumbnail held in an item's JSON
254
+ * @param isGroup Boolean to indicate if the files are associated with a group or item
255
+ * @returns URL string
256
+ */
257
+ export function generateSourceThumbnailUrl(sourcePortalSharingUrl, itemId, thumbnailUrlPart, isGroup = false) {
258
+ return (checkUrlPathTermination(sourcePortalSharingUrl) +
259
+ (isGroup ? "community/groups/" : "content/items/") +
260
+ itemId +
261
+ "/info/" +
262
+ thumbnailUrlPart);
263
+ }
264
+ /**
265
+ * Generates a list of full URLs and folder/filename combinations used to store the resources, metadata,
266
+ * and thumbnail of an item.
267
+ *
268
+ * @param portalSharingUrl Server/sharing
269
+ * @param storageItemId Id of storage item
270
+ * @param resourceFilenames List of resource filenames for an item, e.g., ["file1", "myFolder/file2"]
271
+ * @param storageVersion Version of the Solution template
272
+ * @returns List of item files' URLs and folder/filenames for storing the files
273
+ */
274
+ export function generateStorageFilePaths(portalSharingUrl, storageItemId, resourceFilenames = [], storageVersion = 0) {
275
+ return resourceFilenames.map(resourceFilename => {
276
+ return {
277
+ url: generateSourceResourceUrl(portalSharingUrl, storageItemId, resourceFilename),
278
+ ...convertStorageResourceToItemResource(resourceFilename, storageVersion)
279
+ };
280
+ });
281
+ }
282
+ /**
283
+ * Generates a folder and filename for storing a copy of an item's thumbnail in a storage item.
284
+ *
285
+ * @param itemId Id of item
286
+ * @param thumbnailUrlPart Partial path to the thumbnail held in an item's JSON; can also be a filename
287
+ * @returns Folder and filename for storage; folder is the itemID suffixed with "_info_thumbnail";
288
+ * file is URI-encoded thumbnailUrlPart
289
+ * @see convertStorageResourceToItemResource
290
+ */
291
+ export function generateThumbnailStorageFilename(itemId, thumbnailurl) {
292
+ const folder = itemId + "_info_thumbnail";
293
+ const thumbnailUrlParts = thumbnailurl.split("/");
294
+ const filename = thumbnailUrlParts.length === 1
295
+ ? thumbnailUrlParts[0]
296
+ : thumbnailUrlParts[1];
297
+ return { folder, filename };
298
+ }
299
+ export function isSupportedFileType(filename) {
300
+ // Supported file formats are: .json, .xml, .txt, .png, .pbf, .zip, .jpeg, .jpg, .gif, .bmp, .gz, .svg,
301
+ // .svgz, .geodatabase (https://developers.arcgis.com/rest/users-groups-and-items/add-resources.htm)
302
+ const filenameExtension = filename.match(/\.([a-z]+)$/i);
303
+ const supportedExtensions = "|.json|.xml|.txt|.png|.pbf|.zip|.jpeg|.jpg|.gif|.bmp|.gz|.svg|.svgz|.geodatabase|";
304
+ return (!!filenameExtension &&
305
+ supportedExtensions.indexOf("|" + filenameExtension[0] + "|") >= 0);
306
+ }
307
+ /**
308
+ * Gets the thumbnail of an item or group.
309
+ *
310
+ * @param authentication Credentials for the request to the storage
311
+ * @param filePaths List of item files' URLs and folder/filenames for storing the files
312
+ * @returns A promise which resolves to a boolean indicating if the copies were successful
313
+ */
314
+ export function getThumbnailFromStorageItem(authentication, filePaths) {
315
+ let thumbnailUrl;
316
+ let thumbnailFilename;
317
+ filePaths.forEach(path => {
318
+ if (path.type === EFileType.Thumbnail) {
319
+ thumbnailUrl = path.url;
320
+ thumbnailFilename = path.filename;
321
+ }
322
+ });
323
+ if (!thumbnailUrl) {
324
+ return Promise.resolve(null);
325
+ }
326
+ return getThumbnailFile(thumbnailUrl, thumbnailFilename, authentication);
327
+ }
328
+ /**
329
+ * Removes the item's resource that matches the filename with new content
330
+ *
331
+ * @param itemId Id of the item to remove
332
+ * @param filename Name of the resource file to remove
333
+ * @param authentication Credentials for the request to the storage
334
+ * @returns A promise which resolves with a success true/false response
335
+ */
336
+ export function removeItemResourceFile(itemId, filename, authentication) {
337
+ return removeItemResource({
338
+ id: itemId,
339
+ resource: filename,
340
+ authentication: authentication
341
+ });
342
+ }
343
+ /**
344
+ * Updates the item's resource that matches the filename with new content
345
+ *
346
+ * @param itemId Id of the item to update
347
+ * @param filename Name of the resource file to update; prefix optional (e.g., a/b/file.txt)
348
+ * @param resource The new content to update the resource with
349
+ * @param authentication Credentials for the request to the storage
350
+ * @returns A promise which resolves with a success true/false response
351
+ */
352
+ export function updateItemResourceFile(itemId, filename, resource, authentication) {
353
+ // Prefix has to be specified separately
354
+ const prefixedFilenameParts = filename.split("/");
355
+ const prefix = prefixedFilenameParts.length > 1 ? prefixedFilenameParts.slice(0, prefixedFilenameParts.length - 1).join("/") : undefined;
356
+ const suffix = prefixedFilenameParts[prefixedFilenameParts.length - 1];
357
+ return updateItemResource({
358
+ id: itemId,
359
+ prefix: prefix,
360
+ name: suffix,
361
+ resource,
362
+ authentication: authentication
363
+ });
364
+ }
372
365
  //# sourceMappingURL=resourceHelpers.js.map