@esri/solution-common 3.0.0 → 3.1.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/esm/featureServiceHelpers.js +20 -2
  2. package/dist/esm/featureServiceHelpers.js.map +1 -1
  3. package/dist/esm/resourceHelpers.d.ts +3 -2
  4. package/dist/esm/resourceHelpers.js +4 -3
  5. package/dist/esm/resourceHelpers.js.map +1 -1
  6. package/dist/esm/resources/copyAssociatedFiles.d.ts +17 -2
  7. package/dist/esm/resources/copyAssociatedFiles.js +106 -42
  8. package/dist/esm/resources/copyAssociatedFiles.js.map +1 -1
  9. package/dist/esm/resources/copyResourceIntoZip.js +8 -1
  10. package/dist/esm/resources/copyResourceIntoZip.js.map +1 -1
  11. package/dist/esm/resources/getItemResourcesPaths.js +9 -2
  12. package/dist/esm/resources/getItemResourcesPaths.js.map +1 -1
  13. package/package.json +3 -3
  14. package/dist/node/completeItem.d.ts +0 -29
  15. package/dist/node/completeItem.js +0 -82
  16. package/dist/node/completeItem.js.map +0 -1
  17. package/dist/node/create-hub-request-options.d.ts +0 -29
  18. package/dist/node/create-hub-request-options.js +0 -64
  19. package/dist/node/create-hub-request-options.js.map +0 -1
  20. package/dist/node/deleteHelpers/deleteEmptyGroups.d.ts +0 -24
  21. package/dist/node/deleteHelpers/deleteEmptyGroups.js +0 -42
  22. package/dist/node/deleteHelpers/deleteEmptyGroups.js.map +0 -1
  23. package/dist/node/deleteHelpers/deleteGroupIfEmpty.d.ts +0 -27
  24. package/dist/node/deleteHelpers/deleteGroupIfEmpty.js +0 -97
  25. package/dist/node/deleteHelpers/deleteGroupIfEmpty.js.map +0 -1
  26. package/dist/node/deleteHelpers/deleteSolutionContents.d.ts +0 -38
  27. package/dist/node/deleteHelpers/deleteSolutionContents.js +0 -130
  28. package/dist/node/deleteHelpers/deleteSolutionContents.js.map +0 -1
  29. package/dist/node/deleteHelpers/deleteSolutionFolder.d.ts +0 -29
  30. package/dist/node/deleteHelpers/deleteSolutionFolder.js +0 -79
  31. package/dist/node/deleteHelpers/deleteSolutionFolder.js.map +0 -1
  32. package/dist/node/deleteHelpers/deleteSolutionItem.d.ts +0 -30
  33. package/dist/node/deleteHelpers/deleteSolutionItem.js +0 -54
  34. package/dist/node/deleteHelpers/deleteSolutionItem.js.map +0 -1
  35. package/dist/node/deleteHelpers/index.d.ts +0 -22
  36. package/dist/node/deleteHelpers/index.js +0 -26
  37. package/dist/node/deleteHelpers/index.js.map +0 -1
  38. package/dist/node/deleteHelpers/reconstructBuildOrderIds.d.ts +0 -27
  39. package/dist/node/deleteHelpers/reconstructBuildOrderIds.js +0 -34
  40. package/dist/node/deleteHelpers/reconstructBuildOrderIds.js.map +0 -1
  41. package/dist/node/deleteHelpers/removeItems.d.ts +0 -34
  42. package/dist/node/deleteHelpers/removeItems.js +0 -112
  43. package/dist/node/deleteHelpers/removeItems.js.map +0 -1
  44. package/dist/node/deleteHelpers/reportProgress.d.ts +0 -27
  45. package/dist/node/deleteHelpers/reportProgress.js +0 -46
  46. package/dist/node/deleteHelpers/reportProgress.js.map +0 -1
  47. package/dist/node/deleteSolution.d.ts +0 -55
  48. package/dist/node/deleteSolution.js +0 -107
  49. package/dist/node/deleteSolution.js.map +0 -1
  50. package/dist/node/dependencies.d.ts +0 -26
  51. package/dist/node/dependencies.js +0 -171
  52. package/dist/node/dependencies.js.map +0 -1
  53. package/dist/node/featureServiceHelpers.d.ts +0 -791
  54. package/dist/node/featureServiceHelpers.js +0 -2403
  55. package/dist/node/featureServiceHelpers.js.map +0 -1
  56. package/dist/node/generalHelpers.d.ts +0 -372
  57. package/dist/node/generalHelpers.js +0 -842
  58. package/dist/node/generalHelpers.js.map +0 -1
  59. package/dist/node/get-subscription-info.d.ts +0 -27
  60. package/dist/node/get-subscription-info.js +0 -39
  61. package/dist/node/get-subscription-info.js.map +0 -1
  62. package/dist/node/getDeletableSolutionInfo.d.ts +0 -29
  63. package/dist/node/getDeletableSolutionInfo.js +0 -53
  64. package/dist/node/getDeletableSolutionInfo.js.map +0 -1
  65. package/dist/node/getItemTypeAbbrev.d.ts +0 -19
  66. package/dist/node/getItemTypeAbbrev.js +0 -184
  67. package/dist/node/getItemTypeAbbrev.js.map +0 -1
  68. package/dist/node/getSolutionSummary.d.ts +0 -27
  69. package/dist/node/getSolutionSummary.js +0 -101
  70. package/dist/node/getSolutionSummary.js.map +0 -1
  71. package/dist/node/index.d.ts +0 -44
  72. package/dist/node/index.js +0 -48
  73. package/dist/node/index.js.map +0 -1
  74. package/dist/node/interfaces.d.ts +0 -1321
  75. package/dist/node/interfaces.js +0 -75
  76. package/dist/node/interfaces.js.map +0 -1
  77. package/dist/node/libConnectors.d.ts +0 -73
  78. package/dist/node/libConnectors.js +0 -115
  79. package/dist/node/libConnectors.js.map +0 -1
  80. package/dist/node/migrations/apply-schema.d.ts +0 -24
  81. package/dist/node/migrations/apply-schema.js +0 -36
  82. package/dist/node/migrations/apply-schema.js.map +0 -1
  83. package/dist/node/migrations/is-legacy-solution.d.ts +0 -24
  84. package/dist/node/migrations/is-legacy-solution.js +0 -40
  85. package/dist/node/migrations/is-legacy-solution.js.map +0 -1
  86. package/dist/node/migrations/upgrade-three-dot-one.d.ts +0 -27
  87. package/dist/node/migrations/upgrade-three-dot-one.js +0 -49
  88. package/dist/node/migrations/upgrade-three-dot-one.js.map +0 -1
  89. package/dist/node/migrations/upgrade-three-dot-zero.d.ts +0 -27
  90. package/dist/node/migrations/upgrade-three-dot-zero.js +0 -43
  91. package/dist/node/migrations/upgrade-three-dot-zero.js.map +0 -1
  92. package/dist/node/migrations/upgrade-two-dot-five.d.ts +0 -24
  93. package/dist/node/migrations/upgrade-two-dot-five.js +0 -73
  94. package/dist/node/migrations/upgrade-two-dot-five.js.map +0 -1
  95. package/dist/node/migrations/upgrade-two-dot-four.d.ts +0 -24
  96. package/dist/node/migrations/upgrade-two-dot-four.js +0 -72
  97. package/dist/node/migrations/upgrade-two-dot-four.js.map +0 -1
  98. package/dist/node/migrations/upgrade-two-dot-one.d.ts +0 -7
  99. package/dist/node/migrations/upgrade-two-dot-one.js +0 -39
  100. package/dist/node/migrations/upgrade-two-dot-one.js.map +0 -1
  101. package/dist/node/migrations/upgrade-two-dot-seven.d.ts +0 -23
  102. package/dist/node/migrations/upgrade-two-dot-seven.js +0 -58
  103. package/dist/node/migrations/upgrade-two-dot-seven.js.map +0 -1
  104. package/dist/node/migrations/upgrade-two-dot-six.d.ts +0 -27
  105. package/dist/node/migrations/upgrade-two-dot-six.js +0 -61
  106. package/dist/node/migrations/upgrade-two-dot-six.js.map +0 -1
  107. package/dist/node/migrations/upgrade-two-dot-three.d.ts +0 -23
  108. package/dist/node/migrations/upgrade-two-dot-three.js +0 -55
  109. package/dist/node/migrations/upgrade-two-dot-three.js.map +0 -1
  110. package/dist/node/migrations/upgrade-two-dot-two.d.ts +0 -23
  111. package/dist/node/migrations/upgrade-two-dot-two.js +0 -58
  112. package/dist/node/migrations/upgrade-two-dot-two.js.map +0 -1
  113. package/dist/node/migrations/upgrade-two-dot-zero.d.ts +0 -44
  114. package/dist/node/migrations/upgrade-two-dot-zero.js +0 -95
  115. package/dist/node/migrations/upgrade-two-dot-zero.js.map +0 -1
  116. package/dist/node/migrator.d.ts +0 -25
  117. package/dist/node/migrator.js +0 -77
  118. package/dist/node/migrator.js.map +0 -1
  119. package/dist/node/polyfills.d.ts +0 -40
  120. package/dist/node/polyfills.js +0 -98
  121. package/dist/node/polyfills.js.map +0 -1
  122. package/dist/node/resourceHelpers.d.ts +0 -190
  123. package/dist/node/resourceHelpers.js +0 -390
  124. package/dist/node/resourceHelpers.js.map +0 -1
  125. package/dist/node/resources/add-resource-from-blob.d.ts +0 -26
  126. package/dist/node/resources/add-resource-from-blob.js +0 -52
  127. package/dist/node/resources/add-resource-from-blob.js.map +0 -1
  128. package/dist/node/resources/addMetadataFromBlob.d.ts +0 -25
  129. package/dist/node/resources/addMetadataFromBlob.js +0 -43
  130. package/dist/node/resources/addMetadataFromBlob.js.map +0 -1
  131. package/dist/node/resources/convert-item-resource-to-storage-resource.d.ts +0 -32
  132. package/dist/node/resources/convert-item-resource-to-storage-resource.js +0 -70
  133. package/dist/node/resources/convert-item-resource-to-storage-resource.js.map +0 -1
  134. package/dist/node/resources/convert-storage-resource-to-item-resource.d.ts +0 -29
  135. package/dist/node/resources/convert-storage-resource-to-item-resource.js +0 -70
  136. package/dist/node/resources/convert-storage-resource-to-item-resource.js.map +0 -1
  137. package/dist/node/resources/copyAssociatedFiles.d.ts +0 -52
  138. package/dist/node/resources/copyAssociatedFiles.js +0 -237
  139. package/dist/node/resources/copyAssociatedFiles.js.map +0 -1
  140. package/dist/node/resources/copyDataIntoItem.d.ts +0 -33
  141. package/dist/node/resources/copyDataIntoItem.js +0 -63
  142. package/dist/node/resources/copyDataIntoItem.js.map +0 -1
  143. package/dist/node/resources/copyMetadataIntoItem.d.ts +0 -26
  144. package/dist/node/resources/copyMetadataIntoItem.js +0 -46
  145. package/dist/node/resources/copyMetadataIntoItem.js.map +0 -1
  146. package/dist/node/resources/copyResourceIntoZip.d.ts +0 -33
  147. package/dist/node/resources/copyResourceIntoZip.js +0 -71
  148. package/dist/node/resources/copyResourceIntoZip.js.map +0 -1
  149. package/dist/node/resources/copyZipIntoItem.d.ts +0 -25
  150. package/dist/node/resources/copyZipIntoItem.js +0 -54
  151. package/dist/node/resources/copyZipIntoItem.js.map +0 -1
  152. package/dist/node/resources/createCopyResults.d.ts +0 -25
  153. package/dist/node/resources/createCopyResults.js +0 -36
  154. package/dist/node/resources/createCopyResults.js.map +0 -1
  155. package/dist/node/resources/get-blob.d.ts +0 -26
  156. package/dist/node/resources/get-blob.js +0 -27
  157. package/dist/node/resources/get-blob.js.map +0 -1
  158. package/dist/node/resources/getItemResourcesFilesFromPaths.d.ts +0 -24
  159. package/dist/node/resources/getItemResourcesFilesFromPaths.js +0 -49
  160. package/dist/node/resources/getItemResourcesFilesFromPaths.js.map +0 -1
  161. package/dist/node/resources/getItemResourcesPaths.d.ts +0 -26
  162. package/dist/node/resources/getItemResourcesPaths.js +0 -66
  163. package/dist/node/resources/getItemResourcesPaths.js.map +0 -1
  164. package/dist/node/resources/index.d.ts +0 -29
  165. package/dist/node/resources/index.js +0 -33
  166. package/dist/node/resources/index.js.map +0 -1
  167. package/dist/node/resources/solution-resource.d.ts +0 -35
  168. package/dist/node/resources/solution-resource.js +0 -31
  169. package/dist/node/resources/solution-resource.js.map +0 -1
  170. package/dist/node/resources/transform-resource-paths-to-solution-resources.d.ts +0 -56
  171. package/dist/node/resources/transform-resource-paths-to-solution-resources.js +0 -146
  172. package/dist/node/resources/transform-resource-paths-to-solution-resources.js.map +0 -1
  173. package/dist/node/restHelpers.d.ts +0 -585
  174. package/dist/node/restHelpers.js +0 -1887
  175. package/dist/node/restHelpers.js.map +0 -1
  176. package/dist/node/restHelpersGet.d.ts +0 -288
  177. package/dist/node/restHelpersGet.js +0 -804
  178. package/dist/node/restHelpersGet.js.map +0 -1
  179. package/dist/node/sharing/index.d.ts +0 -16
  180. package/dist/node/sharing/index.js +0 -20
  181. package/dist/node/sharing/index.js.map +0 -1
  182. package/dist/node/sharing/share-item-to-groups.d.ts +0 -26
  183. package/dist/node/sharing/share-item-to-groups.js +0 -44
  184. package/dist/node/sharing/share-item-to-groups.js.map +0 -1
  185. package/dist/node/templatization.d.ts +0 -139
  186. package/dist/node/templatization.js +0 -314
  187. package/dist/node/templatization.js.map +0 -1
  188. package/dist/node/trackingHelpers.d.ts +0 -116
  189. package/dist/node/trackingHelpers.js +0 -217
  190. package/dist/node/trackingHelpers.js.map +0 -1
  191. package/dist/node/velocityHelpers.d.ts +0 -57
  192. package/dist/node/velocityHelpers.js +0 -135
  193. package/dist/node/velocityHelpers.js.map +0 -1
  194. package/dist/node/workforceHelpers.d.ts +0 -115
  195. package/dist/node/workforceHelpers.js +0 -747
  196. package/dist/node/workforceHelpers.js.map +0 -1
  197. package/dist/umd/common.umd.js +0 -15471
  198. package/dist/umd/common.umd.js.map +0 -1
  199. package/dist/umd/common.umd.min.js +0 -19
  200. package/dist/umd/common.umd.min.js.map +0 -1
  201. package/dist/umd/src/completeItem.d.ts +0 -29
  202. package/dist/umd/src/create-hub-request-options.d.ts +0 -29
  203. package/dist/umd/src/deleteHelpers/deleteEmptyGroups.d.ts +0 -24
  204. package/dist/umd/src/deleteHelpers/deleteGroupIfEmpty.d.ts +0 -27
  205. package/dist/umd/src/deleteHelpers/deleteSolutionContents.d.ts +0 -38
  206. package/dist/umd/src/deleteHelpers/deleteSolutionFolder.d.ts +0 -29
  207. package/dist/umd/src/deleteHelpers/deleteSolutionItem.d.ts +0 -30
  208. package/dist/umd/src/deleteHelpers/index.d.ts +0 -22
  209. package/dist/umd/src/deleteHelpers/reconstructBuildOrderIds.d.ts +0 -27
  210. package/dist/umd/src/deleteHelpers/removeItems.d.ts +0 -34
  211. package/dist/umd/src/deleteHelpers/reportProgress.d.ts +0 -27
  212. package/dist/umd/src/deleteSolution.d.ts +0 -55
  213. package/dist/umd/src/dependencies.d.ts +0 -26
  214. package/dist/umd/src/featureServiceHelpers.d.ts +0 -791
  215. package/dist/umd/src/generalHelpers.d.ts +0 -372
  216. package/dist/umd/src/get-subscription-info.d.ts +0 -27
  217. package/dist/umd/src/getDeletableSolutionInfo.d.ts +0 -29
  218. package/dist/umd/src/getItemTypeAbbrev.d.ts +0 -19
  219. package/dist/umd/src/getSolutionSummary.d.ts +0 -27
  220. package/dist/umd/src/index.d.ts +0 -44
  221. package/dist/umd/src/interfaces.d.ts +0 -1321
  222. package/dist/umd/src/libConnectors.d.ts +0 -73
  223. package/dist/umd/src/migrations/apply-schema.d.ts +0 -24
  224. package/dist/umd/src/migrations/is-legacy-solution.d.ts +0 -24
  225. package/dist/umd/src/migrations/upgrade-three-dot-one.d.ts +0 -27
  226. package/dist/umd/src/migrations/upgrade-three-dot-zero.d.ts +0 -27
  227. package/dist/umd/src/migrations/upgrade-two-dot-five.d.ts +0 -24
  228. package/dist/umd/src/migrations/upgrade-two-dot-four.d.ts +0 -24
  229. package/dist/umd/src/migrations/upgrade-two-dot-one.d.ts +0 -7
  230. package/dist/umd/src/migrations/upgrade-two-dot-seven.d.ts +0 -23
  231. package/dist/umd/src/migrations/upgrade-two-dot-six.d.ts +0 -27
  232. package/dist/umd/src/migrations/upgrade-two-dot-three.d.ts +0 -23
  233. package/dist/umd/src/migrations/upgrade-two-dot-two.d.ts +0 -23
  234. package/dist/umd/src/migrations/upgrade-two-dot-zero.d.ts +0 -44
  235. package/dist/umd/src/migrator.d.ts +0 -25
  236. package/dist/umd/src/polyfills.d.ts +0 -40
  237. package/dist/umd/src/resourceHelpers.d.ts +0 -190
  238. package/dist/umd/src/resources/add-resource-from-blob.d.ts +0 -26
  239. package/dist/umd/src/resources/addMetadataFromBlob.d.ts +0 -25
  240. package/dist/umd/src/resources/convert-item-resource-to-storage-resource.d.ts +0 -32
  241. package/dist/umd/src/resources/convert-storage-resource-to-item-resource.d.ts +0 -29
  242. package/dist/umd/src/resources/copyAssociatedFiles.d.ts +0 -52
  243. package/dist/umd/src/resources/copyDataIntoItem.d.ts +0 -33
  244. package/dist/umd/src/resources/copyMetadataIntoItem.d.ts +0 -26
  245. package/dist/umd/src/resources/copyResourceIntoZip.d.ts +0 -33
  246. package/dist/umd/src/resources/copyZipIntoItem.d.ts +0 -25
  247. package/dist/umd/src/resources/createCopyResults.d.ts +0 -25
  248. package/dist/umd/src/resources/get-blob.d.ts +0 -26
  249. package/dist/umd/src/resources/getItemResourcesFilesFromPaths.d.ts +0 -24
  250. package/dist/umd/src/resources/getItemResourcesPaths.d.ts +0 -26
  251. package/dist/umd/src/resources/index.d.ts +0 -29
  252. package/dist/umd/src/resources/solution-resource.d.ts +0 -35
  253. package/dist/umd/src/resources/transform-resource-paths-to-solution-resources.d.ts +0 -56
  254. package/dist/umd/src/restHelpers.d.ts +0 -585
  255. package/dist/umd/src/restHelpersGet.d.ts +0 -288
  256. package/dist/umd/src/sharing/index.d.ts +0 -16
  257. package/dist/umd/src/sharing/share-item-to-groups.d.ts +0 -26
  258. package/dist/umd/src/templatization.d.ts +0 -139
  259. package/dist/umd/src/trackingHelpers.d.ts +0 -116
  260. package/dist/umd/src/velocityHelpers.d.ts +0 -57
  261. package/dist/umd/src/workforceHelpers.d.ts +0 -115
@@ -1,1887 +0,0 @@
1
- "use strict";
2
- /** @license
3
- * Copyright 2018 Esri
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports._getContingentValuesUpdates = exports._getRelationshipUpdates = exports._getFallbackExtent = exports._getCreateServiceOptions = exports._countRelationships = exports._addItemMetadataFile = exports._addItemDataFile = exports.updateItemURL = exports.updateItemTemplateFromDictionary = exports.updateItemExtended = exports.updateGroup = exports.updateItem = exports.shareItem = exports.removeUsers = exports.reassignGroup = exports.searchGroupContents = exports.searchGroupAllContents = exports.searchAllGroups = exports.searchGroups = exports.searchAllItems = exports.searchItems = exports.removeItemOrGroup = exports.removeItem = exports.removeGroup = exports.removeFolder = exports.hasInvalidGroupDesignations = exports._parseAdminServiceData = exports.getFeatureServiceProperties = exports.getServiceLayersAndTables = exports.getRequest = exports._sortRelationships = exports.getLayerUpdates = exports.getLayers = exports.extractDependencies = exports.createUniqueGroup = exports.createUniqueFolder = exports.createItemWithData = exports.createFullItem = exports.createFeatureService = exports.convertExtent = exports.convertExtentWithFallback = exports._validateExtent = exports.convertToISearchOptions = exports.checkRequestStatus = exports.addToServiceDefinition = exports.addTokenToUrl = exports.addForwardItemRelationships = exports.addForwardItemRelationship = exports.getUserSession = exports.rest_request = void 0;
19
- exports._updateItemURL = exports._updateIndexesForRelationshipKeyFields = exports._setItemProperties = exports._reportVariablesInItem = exports._lowercaseDomain = exports._getUpdate = void 0;
20
- /**
21
- * Provides common functions involving the arcgis-rest-js library.
22
- *
23
- * @module restHelpers
24
- */
25
- const featureServiceHelpers_1 = require("./featureServiceHelpers");
26
- const generalHelpers_1 = require("./generalHelpers");
27
- const interfaces_1 = require("./interfaces");
28
- const libConnectors_1 = require("./libConnectors");
29
- const restHelpersGet_1 = require("./restHelpersGet");
30
- const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
31
- const arcgis_rest_request_1 = require("@esri/arcgis-rest-request");
32
- const arcgis_rest_service_admin_1 = require("@esri/arcgis-rest-service-admin");
33
- const workforceHelpers_1 = require("./workforceHelpers");
34
- const templatization_1 = require("./templatization");
35
- const trackingHelpers_1 = require("./trackingHelpers");
36
- // ------------------------------------------------------------------------------------------------------------------ //
37
- var arcgis_rest_request_2 = require("@esri/arcgis-rest-request");
38
- Object.defineProperty(exports, "rest_request", { enumerable: true, get: function () { return arcgis_rest_request_2.request; } });
39
- // ------------------------------------------------------------------------------------------------------------------ //
40
- /**
41
- * Creates a UserSession via a function so that the global arcgisSolution variable can access authentication.
42
- *
43
- * @param options See https://esri.github.io/arcgis-rest-js/api/auth/IUserSessionOptions/
44
- * @returns UserSession
45
- */
46
- function getUserSession(options = {}) {
47
- return new interfaces_1.UserSession(options);
48
- }
49
- exports.getUserSession = getUserSession;
50
- /**
51
- * Adds a forward relationship between two items.
52
- *
53
- * @param originItemId Origin of relationship
54
- * @param destinationItemId Destination of relationship
55
- * @param relationshipType Type of relationship
56
- * @param authentication Credentials for the request
57
- * @returns A Promise to add item resources.
58
- */
59
- function addForwardItemRelationship(originItemId, destinationItemId, relationshipType, authentication) {
60
- return new Promise(resolve => {
61
- const requestOptions = {
62
- originItemId,
63
- destinationItemId,
64
- relationshipType,
65
- authentication
66
- };
67
- (0, arcgis_rest_portal_1.addItemRelationship)(requestOptions).then(response => {
68
- resolve({
69
- success: response.success,
70
- itemId: originItemId
71
- });
72
- }, () => {
73
- resolve({
74
- success: false,
75
- itemId: originItemId
76
- });
77
- });
78
- });
79
- }
80
- exports.addForwardItemRelationship = addForwardItemRelationship;
81
- /**
82
- * Adds forward relationships for an item.
83
- *
84
- * @param originItemId Origin of relationship
85
- * @param destinationRelationships Destinations
86
- * @param authentication Credentials for the request
87
- * @returns A Promise to add item resources.
88
- */
89
- function addForwardItemRelationships(originItemId, destinationRelationships, authentication) {
90
- return new Promise(resolve => {
91
- // Set up relationships using updated relationship information
92
- const relationshipPromises = new Array();
93
- destinationRelationships.forEach(relationship => {
94
- relationship.relatedItemIds.forEach(relatedItemId => {
95
- relationshipPromises.push(addForwardItemRelationship(originItemId, relatedItemId, relationship.relationshipType, authentication));
96
- });
97
- });
98
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
99
- Promise.all(relationshipPromises).then((responses) => resolve(responses));
100
- });
101
- }
102
- exports.addForwardItemRelationships = addForwardItemRelationships;
103
- /**
104
- * Adds a token to the query parameters of a URL.
105
- *
106
- * @param url URL to use as base
107
- * @param authentication Credentials to be used to generate token for URL
108
- * @returns A promise that will resolve with the supplied URL with `token=<token>` added to its query params
109
- * unless either the URL doesn't exist or the token can't be generated
110
- */
111
- function addTokenToUrl(url, authentication) {
112
- return new Promise(resolve => {
113
- if (!url || !authentication) {
114
- resolve(url);
115
- }
116
- else {
117
- authentication.getToken(url).then(token => {
118
- /* istanbul ignore else */
119
- if (token) {
120
- url = (0, generalHelpers_1.appendQueryParam)(url, "token=" + token);
121
- }
122
- resolve(url);
123
- }, () => resolve(url));
124
- }
125
- });
126
- }
127
- exports.addTokenToUrl = addTokenToUrl;
128
- /**
129
- * Calls addToDefinition for the service.
130
- *
131
- * Added retry due to some solutions failing to deploy in specific orgs/hives due to timeouts.
132
- * On the first pass we will use the quicker sync request to add.
133
- * If it fails we will use an async request that will avoid the timeout errors.
134
- *
135
- * @param url URL to use as base
136
- * @param options the info to add to the services definition
137
- * @param skipRetry a boolean to control if retry logic will be used. Defaults to false.
138
- * @param useAsync a boolean to control if we will use an async request
139
- * @returns A promise that will resolve when the request has completed
140
- */
141
- function addToServiceDefinition(url, options, skipRetry = false, useAsync = false) {
142
- /* istanbul ignore else */
143
- if (useAsync) {
144
- options.params = { ...options.params, async: true };
145
- }
146
- return new Promise((resolve, reject) => {
147
- (0, arcgis_rest_service_admin_1.addToServiceDefinition)(url, options).then((result) => {
148
- checkRequestStatus(result, options.authentication).then(() => resolve(null), e => reject((0, generalHelpers_1.fail)(e)));
149
- }, e => {
150
- if (!skipRetry) {
151
- addToServiceDefinition(url, options, true, true).then(() => resolve(null), e => reject(e));
152
- }
153
- else {
154
- reject((0, generalHelpers_1.fail)(e));
155
- }
156
- });
157
- });
158
- }
159
- exports.addToServiceDefinition = addToServiceDefinition;
160
- /**
161
- * When using an async request we need to poll the status url to know when the request has completed or failed.
162
- *
163
- * @param result the result returned from the addToDefinition request.
164
- * This will contain a status url or the standard sync result.
165
- * @param authentication Credentials to be used to generate token for URL
166
- * @returns A promise that will resolve when the request has completed
167
- */
168
- function checkRequestStatus(result, authentication) {
169
- return new Promise((resolve, reject) => {
170
- if (result.statusURL) {
171
- const checkStatus = setInterval(() => {
172
- (0, arcgis_rest_request_1.request)(result.statusURL, { authentication }).then(r => {
173
- /* istanbul ignore else */
174
- if (r.status === "Completed") {
175
- clearInterval(checkStatus);
176
- resolve();
177
- }
178
- else if (r.status === "Failed") {
179
- clearInterval(checkStatus);
180
- reject(r);
181
- }
182
- }, e => {
183
- clearInterval(checkStatus);
184
- reject(e);
185
- });
186
- }, 2000);
187
- }
188
- else {
189
- resolve();
190
- }
191
- });
192
- }
193
- exports.checkRequestStatus = checkRequestStatus;
194
- /**
195
- * Converts a general search into an ISearchOptions structure.
196
- *
197
- * @param search Search specified in one of three ways
198
- * @returns Recast search
199
- */
200
- function convertToISearchOptions(search) {
201
- // Convert the search into an ISearchOptions
202
- let searchOptions = {
203
- q: "",
204
- start: 1,
205
- num: 100
206
- };
207
- if (typeof search === "string") {
208
- // Insert query into defaults
209
- searchOptions.q = search;
210
- }
211
- else if (search instanceof arcgis_rest_portal_1.SearchQueryBuilder) {
212
- // Insert query into defaults
213
- searchOptions.q = search.toParam();
214
- }
215
- else { // search is ISearchOptions
216
- searchOptions = {
217
- ...searchOptions,
218
- ...search // request
219
- };
220
- }
221
- return searchOptions;
222
- }
223
- exports.convertToISearchOptions = convertToISearchOptions;
224
- /**
225
- * Simple validate function to ensure all coordinates are numbers
226
- * In some cases orgs can have null or undefined coordinate values associated with the org extent
227
- *
228
- * @param extent the extent to validate
229
- * @returns the provided extent or a default global extent if some coordinates are not numbers
230
- * @private
231
- */
232
- function _validateExtent(extent) {
233
- // in some cases orgs can have invalid extents defined
234
- // this is a simple validate function that will ensure coordiantes are numbers
235
- // using -179,-89,179,89 because the project call is returning "NaN" when using -180,-90,180,90
236
- const hasInvalid = typeof extent.xmin !== "number" ||
237
- typeof extent.xmax !== "number" ||
238
- typeof extent.ymax !== "number" ||
239
- typeof extent.ymin !== "number";
240
- if (hasInvalid) {
241
- extent.xmin = -179;
242
- extent.xmax = 179;
243
- extent.ymax = 89;
244
- extent.ymin = -89;
245
- extent.spatialReference = { wkid: 4326 };
246
- }
247
- return extent;
248
- }
249
- exports._validateExtent = _validateExtent;
250
- /**
251
- * If the request to convert the extent fails it has commonly been due to an invalid extent.
252
- * This function will first attempt to use the provided extent. If it fails it will default to
253
- * the source items extent and if that fails it will then use a default global extent.
254
- *
255
- * @param extent the extent to convert
256
- * @param fallbackExtent the extent to convert if the main extent does not project to the outSR
257
- * @param outSR the spatial reference to project to
258
- * @param geometryServiceUrl the service url for the geometry service to use
259
- * @param authentication the credentials for the requests
260
- * @returns the extent projected to the provided spatial reference
261
- * or the world extent projected to the provided spatial reference
262
- * @private
263
- */
264
- function convertExtentWithFallback(extent, fallbackExtent, outSR, geometryServiceUrl, authentication) {
265
- return new Promise((resolve, reject) => {
266
- const defaultExtent = {
267
- xmin: -179,
268
- xmax: 179,
269
- ymin: -89,
270
- ymax: 89,
271
- spatialReference: { wkid: 4326 }
272
- };
273
- convertExtent(_validateExtent(extent), outSR, geometryServiceUrl, authentication).then(extentResponse => {
274
- // in some cases project will complete successfully but return "NaN" values
275
- // check for this and call convert again if it does
276
- const extentResponseString = JSON.stringify(extentResponse);
277
- const validatedExtent = JSON.stringify(_validateExtent(extentResponse));
278
- if (extentResponseString === validatedExtent) {
279
- resolve(extentResponse);
280
- }
281
- else {
282
- convertExtent(fallbackExtent || defaultExtent, outSR, geometryServiceUrl, authentication).then(resolve, e => reject((0, generalHelpers_1.fail)(e)));
283
- }
284
- },
285
- // if convert fails try again with default global extent
286
- () => {
287
- convertExtent(defaultExtent, outSR, geometryServiceUrl, authentication).then(resolve, e => reject((0, generalHelpers_1.fail)(e)));
288
- });
289
- });
290
- }
291
- exports.convertExtentWithFallback = convertExtentWithFallback;
292
- /**
293
- * Converts an extent to a specified spatial reference.
294
- *
295
- * @param extent Extent object to check and (possibly) to project
296
- * @param outSR Desired spatial reference
297
- * @param geometryServiceUrl Path to geometry service providing `findTransformations` and `project` services
298
- * @param authentication Credentials for the request
299
- * @returns Original extent if it's already using outSR or the extents projected into the outSR
300
- */
301
- function convertExtent(extent, outSR, geometryServiceUrl, authentication) {
302
- const _requestOptions = { authentication };
303
- return new Promise((resolve, reject) => {
304
- // tslint:disable-next-line:no-unnecessary-type-assertion
305
- if (extent.spatialReference.wkid === outSR?.wkid || !outSR) {
306
- resolve(extent);
307
- }
308
- else {
309
- _requestOptions.params = {
310
- f: "json",
311
- // tslint:disable-next-line:no-unnecessary-type-assertion
312
- inSR: extent.spatialReference.wkid,
313
- outSR: outSR.wkid,
314
- extentOfInterest: JSON.stringify(extent)
315
- };
316
- (0, arcgis_rest_request_1.request)((0, generalHelpers_1.checkUrlPathTermination)(geometryServiceUrl) + "findTransformations", _requestOptions).then(response => {
317
- const transformations = response && response.transformations
318
- ? response.transformations
319
- : undefined;
320
- let transformation;
321
- if (transformations && transformations.length > 0) {
322
- // if a forward single transformation is found use that...otherwise check for and use composite
323
- transformation = transformations[0].wkid
324
- ? transformations[0].wkid
325
- : transformations[0].geoTransforms
326
- ? transformations[0]
327
- : undefined;
328
- }
329
- _requestOptions.params = {
330
- f: "json",
331
- outSR: outSR.wkid,
332
- // tslint:disable-next-line:no-unnecessary-type-assertion
333
- inSR: extent.spatialReference.wkid,
334
- geometries: {
335
- geometryType: "esriGeometryPoint",
336
- geometries: [
337
- { x: extent.xmin, y: extent.ymin },
338
- { x: extent.xmax, y: extent.ymax }
339
- ]
340
- },
341
- transformation: transformation
342
- };
343
- (0, arcgis_rest_request_1.request)((0, generalHelpers_1.checkUrlPathTermination)(geometryServiceUrl) + "project", _requestOptions).then(projectResponse => {
344
- const projectGeom = projectResponse.geometries.length === 2
345
- ? projectResponse.geometries
346
- : undefined;
347
- if (projectGeom) {
348
- resolve({
349
- xmin: projectGeom[0].x,
350
- ymin: projectGeom[0].y,
351
- xmax: projectGeom[1].x,
352
- ymax: projectGeom[1].y,
353
- spatialReference: outSR
354
- });
355
- }
356
- else {
357
- resolve(undefined);
358
- }
359
- }, e => reject((0, generalHelpers_1.fail)(e)));
360
- }, e => reject((0, generalHelpers_1.fail)(e)));
361
- }
362
- });
363
- }
364
- exports.convertExtent = convertExtent;
365
- /**
366
- * Publishes a feature service as an AGOL item; it does not include its layers and tables
367
- *
368
- * @param newItemTemplate Template of item to be created
369
- * @param authentication Credentials for the request
370
- * @param templateDictionary Hash of facts: org URL, adlib replacements, user; .user.folders property contains a list
371
- * @returns A promise that will resolve with an object reporting success and the Solution id
372
- */
373
- function createFeatureService(newItemTemplate, authentication, templateDictionary) {
374
- return new Promise((resolve, reject) => {
375
- // Create item
376
- _getCreateServiceOptions(newItemTemplate, authentication, templateDictionary).then(createOptions => {
377
- (0, arcgis_rest_service_admin_1.createFeatureService)(createOptions).then(createResponse => {
378
- // Federated servers may have inconsistent casing, so lowerCase it
379
- createResponse.encodedServiceURL = _lowercaseDomain(createResponse.encodedServiceURL);
380
- createResponse.serviceurl = _lowercaseDomain(createResponse.serviceurl);
381
- resolve(createResponse);
382
- }, e => reject((0, generalHelpers_1.fail)(e)));
383
- }, e => reject((0, generalHelpers_1.fail)(e)));
384
- });
385
- }
386
- exports.createFeatureService = createFeatureService;
387
- /**
388
- * Publishes an item and its data, metadata, and resources as an AGOL item.
389
- *
390
- * @param itemInfo Item's `item` section
391
- * @param folderId Id of folder to receive item; null indicates that the item goes into the root
392
- * folder; ignored for Group item type
393
- * @param destinationAuthentication Credentials for for requests to where the item is to be created
394
- * @param itemThumbnailUrl URL to image to use for item thumbnail
395
- * @param itemThumbnailAuthentication Credentials for requests to the thumbnail source
396
- * @param dataFile Item's `data` section
397
- * @param metadataFile Item's metadata file
398
- * @param resourcesFiles Item's resources
399
- * @param access Access to set for item: "public", "org", "private"
400
- * @returns A promise that will resolve with an object reporting success or failure and the Solution id
401
- */
402
- function createFullItem(itemInfo, folderId, destinationAuthentication, itemThumbnailUrl, itemThumbnailAuthentication, dataFile, metadataFile, resourcesFiles, access = "private") {
403
- return new Promise((resolve, reject) => {
404
- // Create item
405
- const createOptions = {
406
- item: {
407
- ...itemInfo
408
- },
409
- folderId,
410
- authentication: destinationAuthentication
411
- };
412
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
413
- addTokenToUrl(itemThumbnailUrl, itemThumbnailAuthentication).then(updatedThumbnailUrl => {
414
- /* istanbul ignore else */
415
- if (updatedThumbnailUrl) {
416
- createOptions.item.thumbnailurl = (0, generalHelpers_1.appendQueryParam)(updatedThumbnailUrl, "w=400");
417
- }
418
- (0, arcgis_rest_portal_1.createItemInFolder)(createOptions).then(createResponse => {
419
- if (createResponse.success) {
420
- let accessDef;
421
- // Set access if it is not AGOL default
422
- // Set the access manually since the access value in createItem appears to be ignored
423
- // Need to run serially; will not work reliably if done in parallel with adding the data section
424
- if (access !== "private") {
425
- const accessOptions = {
426
- id: createResponse.id,
427
- access: access === "public" ? "public" : "org",
428
- authentication: destinationAuthentication
429
- };
430
- accessDef = (0, arcgis_rest_portal_1.setItemAccess)(accessOptions);
431
- }
432
- else {
433
- accessDef = Promise.resolve({
434
- itemId: createResponse.id
435
- });
436
- }
437
- // Now add attached items
438
- accessDef.then(() => {
439
- const updateDefs = [];
440
- // Add the data section
441
- if (dataFile) {
442
- updateDefs.push(_addItemDataFile(createResponse.id, dataFile, destinationAuthentication));
443
- }
444
- // Add the resources via a zip because AGO sometimes loses resources if many are added at the
445
- // same time to the same item
446
- if (Array.isArray(resourcesFiles) &&
447
- resourcesFiles.length > 0) {
448
- updateDefs.push(new Promise((rsrcResolve, rsrcReject) => {
449
- (0, libConnectors_1.createZip)("resources.zip", resourcesFiles).then((zipfile) => {
450
- const addResourceOptions = {
451
- id: createResponse.id,
452
- resource: zipfile,
453
- authentication: destinationAuthentication,
454
- params: {
455
- archive: true
456
- }
457
- };
458
- (0, arcgis_rest_portal_1.addItemResource)(addResourceOptions).then(rsrcResolve, rsrcReject);
459
- }, rsrcReject);
460
- }));
461
- }
462
- // Add the metadata section
463
- if (metadataFile) {
464
- updateDefs.push(_addItemMetadataFile(createResponse.id, metadataFile, destinationAuthentication));
465
- }
466
- // Wait until all adds are done
467
- Promise.all(updateDefs).then(() => resolve(createResponse), e => reject((0, generalHelpers_1.fail)(e)));
468
- }, e => reject((0, generalHelpers_1.fail)(e)));
469
- }
470
- else {
471
- reject((0, generalHelpers_1.fail)());
472
- }
473
- }, e => reject((0, generalHelpers_1.fail)(e)));
474
- });
475
- });
476
- }
477
- exports.createFullItem = createFullItem;
478
- /**
479
- * Publishes an item and its data as an AGOL item.
480
- *
481
- * @param itemInfo Item's `item` section
482
- * @param dataInfo Item's `data` section
483
- * @param authentication Credentials for the request
484
- * @param folderId Id of folder to receive item; null indicates that the item goes into the root
485
- * folder; ignored for Group item type
486
- * @param access Access to set for item: "public", "org", "private"
487
- * @returns A promise that will resolve with an object reporting success and the Solution id
488
- */
489
- function createItemWithData(itemInfo, dataInfo, authentication, folderId, access = "private") {
490
- return new Promise((resolve, reject) => {
491
- // Create item
492
- const createOptions = {
493
- item: {
494
- title: "_",
495
- ...itemInfo,
496
- data: dataInfo
497
- },
498
- folderId,
499
- authentication: authentication
500
- };
501
- if (itemInfo.thumbnail) {
502
- createOptions.params = {
503
- // Pass thumbnail file in via params because item property is serialized, which discards a blob
504
- thumbnail: itemInfo.thumbnail
505
- };
506
- delete createOptions.item.thumbnail;
507
- }
508
- (0, arcgis_rest_portal_1.createItemInFolder)(createOptions).then(createResponse => {
509
- if (createResponse.success) {
510
- if (access !== "private") {
511
- // Set access if it is not AGOL default
512
- // Set the access manually since the access value in createItem appears to be ignored
513
- const accessOptions = {
514
- id: createResponse.id,
515
- access: access === "public" ? "public" : "org",
516
- authentication: authentication
517
- };
518
- (0, arcgis_rest_portal_1.setItemAccess)(accessOptions).then(() => {
519
- resolve({
520
- folder: createResponse.folder,
521
- id: createResponse.id,
522
- success: true
523
- });
524
- }, e => reject((0, generalHelpers_1.fail)(e)));
525
- }
526
- else {
527
- resolve({
528
- folder: createResponse.folder,
529
- id: createResponse.id,
530
- success: true
531
- });
532
- }
533
- }
534
- else {
535
- reject((0, generalHelpers_1.fail)());
536
- }
537
- }, e => reject((0, generalHelpers_1.fail)(e)));
538
- });
539
- }
540
- exports.createItemWithData = createItemWithData;
541
- /**
542
- * Creates a folder using a numeric suffix to ensure uniqueness if necessary.
543
- *
544
- * @param title Folder title, used as-is if possible and with suffix otherwise
545
- * @param templateDictionary Hash of facts: org URL, adlib replacements, user; .user.folders property contains a list
546
- * of known folder names; function updates list with existing names not yet known, and creates .user.folders if it
547
- * doesn't exist in the dictionary
548
- * @param authentication Credentials for creating folder
549
- * @returns Id of created folder
550
- */
551
- function createUniqueFolder(title, templateDictionary, authentication) {
552
- return new Promise((resolve, reject) => {
553
- // Get a title that is not already in use
554
- const folderTitle = (0, generalHelpers_1.getUniqueTitle)(title, templateDictionary, "user.folders");
555
- const folderCreationParam = {
556
- title: folderTitle,
557
- authentication: authentication
558
- };
559
- (0, arcgis_rest_portal_1.createFolder)(folderCreationParam).then(ok => resolve(ok), err => {
560
- // If the name already exists, we'll try again
561
- const errorDetails = (0, generalHelpers_1.getProp)(err, "response.error.details");
562
- if (Array.isArray(errorDetails) && errorDetails.length > 0) {
563
- const nameNotAvailMsg = "Folder title '" + folderTitle + "' not available.";
564
- if (errorDetails.indexOf(nameNotAvailMsg) >= 0) {
565
- // Create the user.folders property if it doesn't exist
566
- /* istanbul ignore else */
567
- if (!(0, generalHelpers_1.getProp)(templateDictionary, "user.folders")) {
568
- (0, generalHelpers_1.setCreateProp)(templateDictionary, "user.folders", []);
569
- }
570
- templateDictionary.user.folders.push({
571
- title: folderTitle
572
- });
573
- createUniqueFolder(title, templateDictionary, authentication).then(resolve, reject);
574
- }
575
- else {
576
- reject(err);
577
- }
578
- }
579
- else {
580
- // Otherwise, error out
581
- reject(err);
582
- }
583
- });
584
- });
585
- }
586
- exports.createUniqueFolder = createUniqueFolder;
587
- /**
588
- * Creates a group using numeric suffix to ensure uniqueness.
589
- *
590
- * @param title Group title, used as-is if possible and with suffix otherwise
591
- * @param templateDictionary Hash of facts: org URL, adlib replacements, user
592
- * @param authentication Credentials for creating group
593
- * @param owner Optional arg for the Tracking owner
594
- * If the tracking owner is not the one deploying the solution
595
- * tracker groups will be created under the deployment user but
596
- * will be reassigned to the tracking owner.
597
- * @returns Information about created group
598
- */
599
- function createUniqueGroup(title, groupItem, templateDictionary, authentication, owner) {
600
- return new Promise((resolve, reject) => {
601
- let groupsPromise;
602
- // when working with tracker we need to consider the groups of the deploying user as well as the groups
603
- // of the tracking user...must be unique for both
604
- if (owner && owner !== authentication.username) {
605
- groupsPromise = searchAllGroups(`(owner:${owner}) orgid:${templateDictionary.organization.id}`, authentication);
606
- }
607
- else {
608
- groupsPromise = Promise.resolve([]);
609
- }
610
- // first get the tracker owner groups
611
- groupsPromise.then(groups => {
612
- templateDictionary["allGroups"] =
613
- groups.concat((0, generalHelpers_1.getProp)(templateDictionary, "user.groups"));
614
- // Get a title that is not already in use
615
- groupItem.title = (0, generalHelpers_1.getUniqueTitle)(title, templateDictionary, "allGroups");
616
- const groupCreationParam = {
617
- group: groupItem,
618
- authentication: authentication
619
- };
620
- (0, arcgis_rest_portal_1.createGroup)(groupCreationParam).then(resolve, err => {
621
- // If the name already exists, we'll try again
622
- const errorDetails = (0, generalHelpers_1.getProp)(err, "response.error.details");
623
- if (Array.isArray(errorDetails) && errorDetails.length > 0) {
624
- const nameNotAvailMsg = "You already have a group named '" +
625
- groupItem.title +
626
- "'. Try a different name.";
627
- if (errorDetails.indexOf(nameNotAvailMsg) >= 0) {
628
- templateDictionary.user.groups.push({
629
- title: groupItem.title
630
- });
631
- createUniqueGroup(title, groupItem, templateDictionary, authentication).then(resolve, reject);
632
- }
633
- else {
634
- reject(err);
635
- }
636
- }
637
- else {
638
- // Otherwise, error out
639
- reject(err);
640
- }
641
- });
642
- }, e => reject(e));
643
- });
644
- }
645
- exports.createUniqueGroup = createUniqueGroup;
646
- /**
647
- * Gets the ids of the dependencies of an AGOL feature service item.
648
- * Dependencies will only exist when the service is a view.
649
- *
650
- * @param itemTemplate Template of item to be created
651
- * @param authentication Credentials for the request
652
- * @returns A promise that will resolve a list of dependencies
653
- */
654
- function extractDependencies(itemTemplate, authentication) {
655
- const dependencies = [];
656
- return new Promise((resolve, reject) => {
657
- // Get service dependencies when the item is a view
658
- // This step is skipped for tracker views as they will already have a source service in the org
659
- if (itemTemplate.properties.service.isView && itemTemplate.item.url && !(0, trackingHelpers_1.isTrackingViewTemplate)(itemTemplate)) {
660
- (0, arcgis_rest_request_1.request)((0, generalHelpers_1.checkUrlPathTermination)(itemTemplate.item.url) + "sources?f=json", {
661
- authentication: authentication
662
- }).then(response => {
663
- /* istanbul ignore else */
664
- if (response && response.services) {
665
- response.services.forEach((layer) => {
666
- dependencies.push({
667
- id: layer.serviceItemId,
668
- name: layer.name
669
- });
670
- });
671
- }
672
- resolve(dependencies);
673
- }, e => reject((0, generalHelpers_1.fail)(e)));
674
- }
675
- else if ((0, workforceHelpers_1.isWorkforceProject)(itemTemplate)) {
676
- resolve((0, workforceHelpers_1.getWorkforceDependencies)(itemTemplate, dependencies));
677
- }
678
- else {
679
- resolve(dependencies);
680
- }
681
- });
682
- }
683
- exports.extractDependencies = extractDependencies;
684
- /**
685
- * Get json info for the services layers
686
- *
687
- * @param serviceUrl the url for the service
688
- * @param layerList list of base layer info
689
- * @param authentication Credentials for the request
690
- * @returns A promise that will resolve a list of dependencies
691
- */
692
- function getLayers(serviceUrl, layerList, authentication) {
693
- return new Promise((resolve, reject) => {
694
- if (layerList.length === 0) {
695
- resolve([]);
696
- }
697
- // get the admin URL
698
- serviceUrl = serviceUrl.replace("/rest/services", "/rest/admin/services");
699
- const requestsDfd = [];
700
- layerList.forEach(layer => {
701
- const requestOptions = {
702
- authentication: authentication
703
- };
704
- requestsDfd.push((0, arcgis_rest_request_1.request)((0, generalHelpers_1.checkUrlPathTermination)(serviceUrl) + layer["id"] + "?f=json", requestOptions));
705
- });
706
- // Wait until all layers are heard from
707
- Promise.all(requestsDfd).then(layers => resolve(layers), e => reject((0, generalHelpers_1.fail)(e)));
708
- });
709
- }
710
- exports.getLayers = getLayers;
711
- /**
712
- * Add additional options to a layers definition.
713
- *
714
- * @param args The IPostProcessArgs for the request(s)
715
- * @param isPortal boolean to indicate if we are deploying to portal
716
- *
717
- * @returns An array of update instructions
718
- * @private
719
- */
720
- function getLayerUpdates(args, isPortal) {
721
- const adminUrl = args.itemTemplate.item.url.replace("rest/services", "rest/admin/services");
722
- const updates = [];
723
- const refresh = _getUpdate(adminUrl, null, null, args, "refresh");
724
- updates.push(refresh);
725
- Object.keys(args.objects).forEach(id => {
726
- const obj = Object.assign({}, args.objects[id]);
727
- // These properties cannot be set in the update definition when working with portal
728
- if (isPortal) {
729
- (0, generalHelpers_1.deleteProps)(obj, ["type", "id", "relationships", "sourceServiceFields"]);
730
- }
731
- // handle definition deletes
732
- // removes previous editFieldsInfo fields if their names were changed
733
- if (obj.hasOwnProperty("deleteFields")) {
734
- updates.push(_getUpdate(adminUrl, id, obj, args, "delete"));
735
- (0, generalHelpers_1.deleteProp)(obj, "deleteFields");
736
- updates.push(_getUpdate(adminUrl, null, null, args, "refresh"));
737
- }
738
- });
739
- // issue: #706
740
- // Add source service relationships
741
- // views will now always add all layers in a single call and will inherit the relationships from the source service
742
- if (!args.itemTemplate.properties.service.isView) {
743
- const relUpdates = _getRelationshipUpdates({
744
- message: "updated layer relationships",
745
- objects: args.objects,
746
- itemTemplate: args.itemTemplate,
747
- authentication: args.authentication
748
- });
749
- // issue: #724
750
- // In portal the order the relationships are added needs to follow the layer order
751
- // otherwise the relationship IDs will be reset
752
- relUpdates.layers = _sortRelationships(args.itemTemplate.properties.layers, args.itemTemplate.properties.tables, relUpdates);
753
- /* istanbul ignore else */
754
- if (relUpdates.layers.length > 0) {
755
- updates.push(_getUpdate(adminUrl, null, relUpdates, args, "add"));
756
- updates.push(refresh);
757
- }
758
- // handle contingent values
759
- const contingentValuesUpdates = _getContingentValuesUpdates({
760
- message: "add layer contingent values",
761
- objects: args.objects,
762
- itemTemplate: args.itemTemplate,
763
- authentication: args.authentication
764
- });
765
- /* istanbul ignore else */
766
- if (contingentValuesUpdates.length > 0) {
767
- contingentValuesUpdates.forEach(conUpdate => {
768
- updates.push(_getUpdate(adminUrl + conUpdate.id, null, conUpdate.contingentValues, args, "add"));
769
- });
770
- }
771
- }
772
- return updates.length === 1 ? [] : updates;
773
- }
774
- exports.getLayerUpdates = getLayerUpdates;
775
- /**
776
- * Sorts relationships based on order of supporting layers and tables in the service definition
777
- *
778
- * @param layers the layers from the service
779
- * @param tables the tables from the service
780
- * @param relUpdates the relationships to add for the service
781
- *
782
- * @returns An array with relationships that have been sorted
783
- * @private
784
- */
785
- function _sortRelationships(layers, tables, relUpdates) {
786
- const ids = [].concat(layers.map((l) => l.id), tables.map((t) => t.id));
787
- // In portal the order the relationships are added needs to follow the layer order
788
- // otherwise the relationship IDs will be reset
789
- const _relUpdateLayers = [];
790
- ids.forEach(id => {
791
- relUpdates.layers.some((relUpdate) => {
792
- if (id === relUpdate.id) {
793
- _relUpdateLayers.push(relUpdate);
794
- return true;
795
- }
796
- else {
797
- return false;
798
- }
799
- });
800
- });
801
- return _relUpdateLayers;
802
- }
803
- exports._sortRelationships = _sortRelationships;
804
- /**
805
- * Add additional options to a layers definition
806
- *
807
- * Added retry due to some solutions failing to deploy in specific orgs/hives
808
- *
809
- *
810
- * @param Update will contain either add, update, or delete from service definition call
811
- * @param skipRetry defaults to false. when true the retry logic will be ignored
812
- * @returns A promise that will resolve when service definition call has completed
813
- * @private
814
- */
815
- /* istanbul ignore else */
816
- function getRequest(update, skipRetry = false, useAsync = false) {
817
- return new Promise((resolve, reject) => {
818
- const options = {
819
- params: update.params,
820
- authentication: update.args.authentication
821
- };
822
- /* istanbul ignore else */
823
- if ((useAsync && update.url.indexOf("addToDefinition") > -1) ||
824
- update.url.indexOf("updateDefinition") > -1 ||
825
- update.url.indexOf("deleteFromDefinition") > -1) {
826
- options.params = { ...options.params, async: true };
827
- }
828
- (0, arcgis_rest_request_1.request)(update.url, options).then(result => {
829
- checkRequestStatus(result, options.authentication).then(() => resolve(null), e => reject((0, generalHelpers_1.fail)(e)));
830
- }, (e) => {
831
- if (!skipRetry) {
832
- getRequest(update, true, true).then(() => resolve(), e => reject(e));
833
- }
834
- else {
835
- reject(e);
836
- }
837
- });
838
- });
839
- }
840
- exports.getRequest = getRequest;
841
- /**
842
- * Fills in missing data, including full layer and table definitions, in a feature services' definition.
843
- *
844
- * @param itemTemplate Feature service item, data, dependencies definition to be modified
845
- * @param authentication Credentials for the request to AGOL
846
- * @returns A promise that will resolve when fullItem has been updated
847
- * @private
848
- */
849
- function getServiceLayersAndTables(itemTemplate, authentication) {
850
- return new Promise((resolve, reject) => {
851
- // To have enough information for reconstructing the service, we'll supplement
852
- // the item and data sections with sections for the service, full layers, and
853
- // full tables
854
- // Extra steps must be taken for workforce version 2
855
- const isWorkforceService = (0, workforceHelpers_1.isWorkforceProject)(itemTemplate);
856
- // Get the service description
857
- if (itemTemplate.item.url) {
858
- getFeatureServiceProperties(itemTemplate.item.url, authentication, isWorkforceService).then(properties => {
859
- itemTemplate.properties = properties;
860
- resolve(itemTemplate);
861
- }, e => reject((0, generalHelpers_1.fail)(e)));
862
- }
863
- else {
864
- resolve(itemTemplate);
865
- }
866
- });
867
- }
868
- exports.getServiceLayersAndTables = getServiceLayersAndTables;
869
- /**
870
- * Get service properties for the given url and update key props
871
- *
872
- * @param serviceUrl the feature service url
873
- * @param authentication Credentials for the request to AGOL
874
- * @param workforceService boolean to indicate if extra workforce service steps should be handled
875
- * @returns A promise that will resolve with the service properties
876
- * @private
877
- */
878
- function getFeatureServiceProperties(serviceUrl, authentication, workforceService = false) {
879
- return new Promise((resolve, reject) => {
880
- const properties = {
881
- service: {},
882
- layers: [],
883
- tables: []
884
- };
885
- // get the admin URL
886
- serviceUrl = serviceUrl.replace("/rest/services", "/rest/admin/services");
887
- // Get the service description
888
- (0, arcgis_rest_request_1.request)(serviceUrl + "?f=json", {
889
- authentication: authentication
890
- }).then(serviceData => {
891
- properties.service = _parseAdminServiceData(serviceData);
892
- // Copy cacheMaxAge to top level so that AGO sees it when deploying the service
893
- // serviceData may have set it if there isn't an adminServiceInfo
894
- /* istanbul ignore else */
895
- if (serviceData.adminServiceInfo?.cacheMaxAge) {
896
- properties.service.cacheMaxAge =
897
- serviceData.adminServiceInfo.cacheMaxAge;
898
- }
899
- // Move the layers and tables out of the service's data section
900
- /* istanbul ignore else */
901
- if (serviceData.layers) {
902
- properties.layers = serviceData.layers;
903
- // Fill in properties that the service layer doesn't provide
904
- // and remove properties that should not exist in the template
905
- properties.layers.forEach(layer => {
906
- layer.serviceItemId = properties.service.serviceItemId;
907
- layer.extent = null;
908
- (0, featureServiceHelpers_1.removeLayerOptimization)(layer);
909
- });
910
- }
911
- delete serviceData.layers;
912
- /* istanbul ignore else */
913
- if (serviceData.tables) {
914
- properties.tables = serviceData.tables;
915
- // Fill in properties that the service layer doesn't provide
916
- properties.tables.forEach(table => {
917
- table.serviceItemId = properties.service.serviceItemId;
918
- table.extent = null;
919
- });
920
- }
921
- delete serviceData.tables;
922
- // Ensure solution items have unique indexes on relationship key fields
923
- _updateIndexesForRelationshipKeyFields(properties);
924
- (0, featureServiceHelpers_1.processContingentValues)(properties, serviceUrl, authentication).then(() => {
925
- if (workforceService) {
926
- (0, workforceHelpers_1.getWorkforceServiceInfo)(properties, serviceUrl, authentication).then(resolve, reject);
927
- }
928
- else {
929
- resolve(properties);
930
- }
931
- }, (e) => reject((0, generalHelpers_1.fail)(e)));
932
- }, (e) => reject((0, generalHelpers_1.fail)(e)));
933
- });
934
- }
935
- exports.getFeatureServiceProperties = getFeatureServiceProperties;
936
- /**
937
- * Parses the layers array and will filter subsets of Layers and Tables
938
- * Layers and Tables are both returned in the layers array when we access a feature service from the admin api.
939
- *
940
- * @param adminData The data of the feature service
941
- * @returns A mutated version of the provided adminData
942
- * @private
943
- */
944
- function _parseAdminServiceData(adminData) {
945
- const layers = adminData.layers || [];
946
- const tables = adminData.tables || [];
947
- (0, generalHelpers_1.setCreateProp)(adminData, "layers", layers.filter(l => l.type === "Feature Layer"));
948
- // TODO understand if the concat is necessary.
949
- // Not sure if the admin api will ever actually return a tables collection here.
950
- (0, generalHelpers_1.setCreateProp)(adminData, "tables", tables.concat(layers.filter(l => l.type === "Table")));
951
- return adminData;
952
- }
953
- exports._parseAdminServiceData = _parseAdminServiceData;
954
- /**
955
- * livingatlas designation test.
956
- * These layers should not be templatized or depolyed
957
- *
958
- * @param groupDesignations the items group designations to evaluate
959
- * @returns A boolean indicating if the invalid designation is found in the item info
960
- */
961
- function hasInvalidGroupDesignations(groupDesignations) {
962
- const invalidGroupDesignations = ["livingatlas"];
963
- return groupDesignations
964
- ? invalidGroupDesignations.indexOf(groupDesignations) > -1
965
- : false;
966
- }
967
- exports.hasInvalidGroupDesignations = hasInvalidGroupDesignations;
968
- /**
969
- * Removes a folder from AGO.
970
- *
971
- * @param folderId Id of a folder to delete
972
- * @param authentication Credentials for the request to AGO
973
- * @returns A promise that will resolve with the result of the request
974
- */
975
- function removeFolder(folderId, authentication) {
976
- return new Promise((resolve, reject) => {
977
- const requestOptions = {
978
- folderId: folderId,
979
- authentication: authentication
980
- };
981
- (0, arcgis_rest_portal_1.removeFolder)(requestOptions).then(result => (result.success ? resolve(result) : reject(result)), reject);
982
- });
983
- }
984
- exports.removeFolder = removeFolder;
985
- /**
986
- * Removes a group from AGO.
987
- *
988
- * @param groupId Id of a group to delete
989
- * @param authentication Credentials for the request to AGO
990
- * @returns A promise that will resolve with the result of the request
991
- */
992
- function removeGroup(groupId, authentication) {
993
- return new Promise((resolve, reject) => {
994
- const requestOptions = {
995
- id: groupId,
996
- authentication: authentication
997
- };
998
- (0, arcgis_rest_portal_1.removeGroup)(requestOptions).then(result => (result.success ? resolve(result) : reject(result)), reject);
999
- });
1000
- }
1001
- exports.removeGroup = removeGroup;
1002
- /**
1003
- * Removes an item from AGO.
1004
- *
1005
- * @param itemId Id of an item to delete
1006
- * @param authentication Credentials for the request to AGO
1007
- * @returns A promise that will resolve with the result of the request
1008
- */
1009
- function removeItem(itemId, authentication) {
1010
- return new Promise((resolve, reject) => {
1011
- const requestOptions = {
1012
- id: itemId,
1013
- authentication: authentication
1014
- };
1015
- (0, arcgis_rest_portal_1.removeItem)(requestOptions).then(result => (result.success ? resolve(result) : reject(result)), reject);
1016
- });
1017
- }
1018
- exports.removeItem = removeItem;
1019
- /**
1020
- * Removes an item or group from AGO.
1021
- *
1022
- * @param itemId Id of an item or group to delete
1023
- * @param authentication Credentials for the request to AGO
1024
- * @returns A promise that will resolve with the result of the request
1025
- */
1026
- function removeItemOrGroup(itemId, authentication) {
1027
- return new Promise((resolve, reject) => {
1028
- removeItem(itemId, authentication).then(resolve, error => {
1029
- removeGroup(itemId, authentication).then(resolve, () => reject(error));
1030
- });
1031
- });
1032
- }
1033
- exports.removeItemOrGroup = removeItemOrGroup;
1034
- /**
1035
- * Searches for items matching a query and that the caller has access to.
1036
- *
1037
- * @param search Search string (e.g., "q=redlands+map") or a more detailed structure that can include authentication
1038
- * @returns Promise resolving with search results
1039
- * @see https://developers.arcgis.com/rest/users-groups-and-items/search.htm
1040
- */
1041
- function searchItems(search) {
1042
- return (0, arcgis_rest_portal_1.searchItems)(search);
1043
- }
1044
- exports.searchItems = searchItems;
1045
- /**
1046
- * Searches for items matching a query and that the caller has access to, continuing recursively until done.
1047
- *
1048
- * @param search Search string (e.g., "q=redlands+map") or a more detailed structure that can include authentication
1049
- * @param accumulatedResponse Response built from previous requests
1050
- * @returns Promise resolving with search results
1051
- * @see https://developers.arcgis.com/rest/users-groups-and-items/search.htm
1052
- */
1053
- function searchAllItems(search, accumulatedResponse) {
1054
- // Convert the search into an ISearchOptions
1055
- const searchOptions = convertToISearchOptions(search);
1056
- // Provide a base into which results can be concatenated
1057
- const completeResponse = accumulatedResponse ? accumulatedResponse : {
1058
- query: searchOptions.q,
1059
- start: 1,
1060
- num: 100,
1061
- nextStart: -1,
1062
- total: 0,
1063
- results: []
1064
- };
1065
- return new Promise((resolve, reject) => {
1066
- searchItems(search).then(response => {
1067
- completeResponse.results = completeResponse.results.concat(response.results);
1068
- completeResponse.num = completeResponse.total = completeResponse.results.length;
1069
- if (response.nextStart > 0) {
1070
- // Insert nextStart into next query
1071
- searchOptions.start = response.nextStart;
1072
- resolve(searchAllItems(searchOptions, completeResponse));
1073
- }
1074
- else {
1075
- resolve(completeResponse);
1076
- }
1077
- }, e => reject(e));
1078
- });
1079
- }
1080
- exports.searchAllItems = searchAllItems;
1081
- /**
1082
- * Searches for groups matching criteria.
1083
- *
1084
- * @param searchString Text for which to search, e.g., 'redlands+map', 'type:"Web Map" -type:"Web Mapping Application"'
1085
- * @param authentication Credentials for the request to AGO
1086
- * @param additionalSearchOptions Adjustments to search, such as tranche size
1087
- * @returns A promise that will resolve with a structure with a tranche of results and
1088
- * describing how many items are available
1089
- * @see https://developers.arcgis.com/rest/users-groups-and-items/group-search.htm
1090
- * @see https://developers.arcgis.com/rest/users-groups-and-items/search-reference.htm
1091
- */
1092
- function searchGroups(searchString, authentication, additionalSearchOptions) {
1093
- const searchOptions = {
1094
- q: searchString,
1095
- params: {
1096
- ...additionalSearchOptions
1097
- },
1098
- authentication: authentication
1099
- };
1100
- return (0, arcgis_rest_portal_1.searchGroups)(searchOptions);
1101
- }
1102
- exports.searchGroups = searchGroups;
1103
- /**
1104
- * Searches for groups matching criteria recurusively.
1105
- *
1106
- * @param searchString Text for which to search, e.g., 'redlands+map', 'type:"Web Map" -type:"Web Mapping Application"'
1107
- * @param authentication Credentials for the request to AGO
1108
- * @param groups List of groups that have been found from previous requests
1109
- * @param inPagingParams The paging params for the recurisve searching
1110
- *
1111
- * @returns A promise that will resolve with all groups that meet the search criteria
1112
- */
1113
- function searchAllGroups(searchString, authentication, groups, inPagingParams) {
1114
- const pagingParams = inPagingParams ? inPagingParams : {
1115
- start: 1,
1116
- num: 24
1117
- };
1118
- const additionalSearchOptions = {
1119
- sortField: "title",
1120
- sortOrder: "asc",
1121
- ...pagingParams
1122
- };
1123
- // Provide a base onto which results can be concatenated
1124
- let finalResults = groups ? groups : [];
1125
- return new Promise((resolve, reject) => {
1126
- searchGroups(searchString, authentication, additionalSearchOptions).then(response => {
1127
- finalResults = finalResults.concat(response.results);
1128
- if (response.nextStart > 0) {
1129
- pagingParams.start = response.nextStart;
1130
- resolve(searchAllGroups(searchString, authentication, finalResults, pagingParams));
1131
- }
1132
- else {
1133
- resolve(finalResults);
1134
- }
1135
- }, e => reject(e));
1136
- });
1137
- }
1138
- exports.searchAllGroups = searchAllGroups;
1139
- /**
1140
- * Searches for group contents matching criteria recursively.
1141
- *
1142
- * @param groupId Group whose contents are to be searched
1143
- * @param searchString Text for which to search, e.g., 'redlands+map', 'type:"Web Map" -type:"Web Mapping Application"'
1144
- * @param authentication Credentials for the request to AGO
1145
- * @param additionalSearchOptions Adjustments to search, such as tranche size and categories of interest; categories
1146
- * are supplied as an array: each array element consists of one or more categories to be ORed; array elements are ANDed
1147
- * @param portalUrl Rest Url of the portal to perform the search
1148
- * @param accumulatedResponse Response built from previous requests
1149
- * @returns A promise that will resolve with a structure with a tranche of results and
1150
- * describing how many items are available
1151
- * @see https://developers.arcgis.com/rest/users-groups-and-items/group-content-search.htm
1152
- * @see https://developers.arcgis.com/rest/users-groups-and-items/search-reference.htm
1153
- */
1154
- function searchGroupAllContents(groupId, searchString, authentication, additionalSearchOptions, portalUrl, accumulatedResponse) {
1155
- additionalSearchOptions = additionalSearchOptions ? additionalSearchOptions : {};
1156
- // Provide a base into which results can be concatenated
1157
- const completeResponse = accumulatedResponse ? accumulatedResponse : {
1158
- query: searchString,
1159
- start: 1,
1160
- num: 100,
1161
- nextStart: -1,
1162
- total: 0,
1163
- results: []
1164
- };
1165
- return new Promise((resolve, reject) => {
1166
- searchGroupContents(groupId, searchString, authentication, additionalSearchOptions, portalUrl).then(response => {
1167
- completeResponse.results = completeResponse.results.concat(response.results);
1168
- completeResponse.num = completeResponse.total = completeResponse.results.length;
1169
- if (response.nextStart > 0) {
1170
- additionalSearchOptions.start = response.nextStart;
1171
- resolve(searchGroupAllContents(groupId, searchString, authentication, additionalSearchOptions, portalUrl, completeResponse));
1172
- }
1173
- else {
1174
- resolve(completeResponse);
1175
- }
1176
- }, e => reject(e));
1177
- });
1178
- }
1179
- exports.searchGroupAllContents = searchGroupAllContents;
1180
- /**
1181
- * Searches for group contents matching criteria.
1182
- *
1183
- * @param groupId Group whose contents are to be searched
1184
- * @param searchString Text for which to search, e.g., 'redlands+map', 'type:"Web Map" -type:"Web Mapping Application"'
1185
- * @param authentication Credentials for the request to AGO
1186
- * @param additionalSearchOptions Adjustments to search, such as tranche size and categories of interest; categories
1187
- * are supplied as an array: each array element consists of one or more categories to be ORed; array elements are ANDed
1188
- * @param portalUrl Rest Url of the portal to perform the search
1189
- * @returns A promise that will resolve with a structure with a tranche of results and
1190
- * describing how many items are available
1191
- * @see https://developers.arcgis.com/rest/users-groups-and-items/group-content-search.htm
1192
- * @see https://developers.arcgis.com/rest/users-groups-and-items/search-reference.htm
1193
- */
1194
- function searchGroupContents(groupId, searchString, authentication, additionalSearchOptions, portalUrl) {
1195
- const searchOptions = {
1196
- groupId,
1197
- q: searchString,
1198
- params: Object.assign({
1199
- num: 100
1200
- }, additionalSearchOptions),
1201
- authentication: authentication,
1202
- portal: portalUrl
1203
- };
1204
- // If search options include `categories`, switch to new arcgis-rest-js format
1205
- /* istanbul ignore else */
1206
- if (Array.isArray(searchOptions.params.categories)) {
1207
- searchOptions.params.categories = searchOptions.params.categories.map(andGroup => andGroup.split(","));
1208
- }
1209
- return (0, arcgis_rest_portal_1.searchGroupContent)(searchOptions);
1210
- }
1211
- exports.searchGroupContents = searchGroupContents;
1212
- /**
1213
- * Reassign ownership of a group
1214
- *
1215
- * @param groupId Group to remove users from
1216
- * @param userName The new owner for the group
1217
- * @param authentication Credentials for the request to
1218
- *
1219
- * @returns A promise that will resolve after the group ownership has been assigned
1220
- *
1221
- */
1222
- function reassignGroup(groupId, userName, authentication) {
1223
- const requestOptions = {
1224
- authentication: authentication,
1225
- params: {
1226
- targetUsername: userName
1227
- }
1228
- };
1229
- return (0, arcgis_rest_request_1.request)(`${authentication.portal}/community/groups/${groupId}/reassign`, requestOptions);
1230
- }
1231
- exports.reassignGroup = reassignGroup;
1232
- /**
1233
- * Remove users from a group
1234
- *
1235
- * @param groupId Group to remove users from
1236
- * @param users List of users to remove from the group
1237
- * @param authentication Credentials for the request to
1238
- *
1239
- * @returns A promise that will resolve after the users have been removed
1240
- *
1241
- */
1242
- function removeUsers(groupId, users, authentication) {
1243
- return (0, arcgis_rest_portal_1.removeGroupUsers)({
1244
- id: groupId,
1245
- users,
1246
- authentication
1247
- });
1248
- }
1249
- exports.removeUsers = removeUsers;
1250
- /**
1251
- * Shares an item to the defined group
1252
- *
1253
- * @param groupId Group to share with
1254
- * @param id the item id to share with the group
1255
- * @param destinationAuthentication Credentials for the request to AGO
1256
- * @param owner owner of the group when sharing tracking items (can be different from the deploying user)
1257
- *
1258
- * @returns A promise that will resolve after the item has been shared
1259
- *
1260
- */
1261
- function shareItem(groupId, id, destinationAuthentication, owner) {
1262
- return new Promise((resolve, reject) => {
1263
- const shareOptions = {
1264
- groupId,
1265
- id,
1266
- authentication: destinationAuthentication
1267
- };
1268
- /* istanbul ignore else */
1269
- if (owner) {
1270
- shareOptions.owner = owner;
1271
- }
1272
- (0, arcgis_rest_portal_1.shareItemWithGroup)(shareOptions).then(() => resolve(null), (e) => reject((0, generalHelpers_1.fail)(e)));
1273
- });
1274
- }
1275
- exports.shareItem = shareItem;
1276
- /**
1277
- * Updates an item.
1278
- *
1279
- * @param itemInfo The base info of an item; note that this content will be serialized, which doesn't work
1280
- * for binary content
1281
- * @param authentication Credentials for request
1282
- * @param folderId Item's folder
1283
- * @param additionalParams Updates that are put under the `params` property, which is not serialized
1284
- * @return
1285
- */
1286
- function updateItem(itemInfo, authentication, folderId, additionalParams) {
1287
- return new Promise((resolve, reject) => {
1288
- const updateOptions = {
1289
- item: itemInfo,
1290
- folderId: folderId,
1291
- authentication: authentication,
1292
- params: {
1293
- ...(additionalParams ?? {})
1294
- }
1295
- };
1296
- (0, arcgis_rest_portal_1.updateItem)(updateOptions).then(response => (response.success ? resolve(response) : reject(response)), err => reject(err));
1297
- });
1298
- }
1299
- exports.updateItem = updateItem;
1300
- /**
1301
- * Updates a group.
1302
- *
1303
- * @param groupInfo The base info of a group; note that this content will be serialized, which doesn't work
1304
- * for binary content
1305
- * @param authentication Credentials for request
1306
- * @param additionalParams Updates that are put under the `params` property, which is not serialized
1307
- * @returns A Promise that will resolve with the success/failure status of the request
1308
- */
1309
- function updateGroup(groupInfo, authentication, additionalParams) {
1310
- return new Promise((resolve, reject) => {
1311
- const updateOptions = {
1312
- group: groupInfo,
1313
- authentication,
1314
- params: {
1315
- ...(additionalParams ?? {})
1316
- }
1317
- };
1318
- (0, arcgis_rest_portal_1.updateGroup)(updateOptions).then(response => (response.success ? resolve(response) : reject(response)), err => reject(err));
1319
- });
1320
- }
1321
- exports.updateGroup = updateGroup;
1322
- /**
1323
- * Updates an item.
1324
- *
1325
- * @param itemInfo The base info of an item
1326
- * @param data The items data section
1327
- * @param authentication Credentials for requests
1328
- * @param thumbnail optional thumbnail to update
1329
- * @param access "public" or "org"
1330
- * @return
1331
- */
1332
- function updateItemExtended(itemInfo, data, authentication, thumbnail, access, templateDictionary) {
1333
- return new Promise((resolve, reject) => {
1334
- const updateOptions = {
1335
- item: itemInfo,
1336
- params: {
1337
- text: data || {} // AGO ignores update if `data` is empty
1338
- },
1339
- authentication: authentication
1340
- };
1341
- if (thumbnail) {
1342
- updateOptions.params.thumbnail = thumbnail;
1343
- }
1344
- if ((0, trackingHelpers_1.isTrackingViewTemplate)(undefined, itemInfo) && templateDictionary) {
1345
- updateOptions.owner = templateDictionary.locationTracking.owner;
1346
- }
1347
- (0, arcgis_rest_portal_1.updateItem)(updateOptions).then(result => {
1348
- if (access && access !== "private") {
1349
- // Set access if it is not AGOL default
1350
- // Set the access manually since the access value in createItem appears to be ignored
1351
- const accessOptions = {
1352
- id: itemInfo.id,
1353
- access: access === "public" ? "public" : "org",
1354
- authentication: authentication
1355
- };
1356
- (0, arcgis_rest_portal_1.setItemAccess)(accessOptions).then(() => resolve(result), e => reject((0, generalHelpers_1.fail)(e)));
1357
- }
1358
- else {
1359
- resolve(result);
1360
- }
1361
- }, e => reject((0, generalHelpers_1.fail)(e)));
1362
- });
1363
- }
1364
- exports.updateItemExtended = updateItemExtended;
1365
- /**
1366
- * Update an item's base and data using a dictionary.
1367
- *
1368
- * @param {string} itemId The item ID
1369
- * @param {any} templateDictionary The template dictionary
1370
- * @param {UserSession} authentication The destination session info
1371
- * @returns Promise resolving to successfulness of update
1372
- */
1373
- function updateItemTemplateFromDictionary(itemId, templateDictionary, authentication) {
1374
- return new Promise((resolve, reject) => {
1375
- // Fetch the items as stored in AGO
1376
- Promise.all([
1377
- (0, restHelpersGet_1.getItemBase)(itemId, authentication),
1378
- (0, restHelpersGet_1.getItemDataAsJson)(itemId, authentication)
1379
- ])
1380
- .then(([item, data]) => {
1381
- // Do they have any variables?
1382
- if ((0, templatization_1.hasUnresolvedVariables)(item) || (0, templatization_1.hasUnresolvedVariables)(data)) {
1383
- // Update if so
1384
- const { item: updatedItem, data: updatedData } = (0, templatization_1.replaceInTemplate)({ item, data }, templateDictionary);
1385
- _reportVariablesInItem(itemId, item.type, updatedItem, updatedData);
1386
- return updateItemExtended(updatedItem, updatedData, authentication);
1387
- }
1388
- else {
1389
- // Shortcut out if not
1390
- return Promise.resolve({
1391
- success: true,
1392
- id: itemId
1393
- });
1394
- }
1395
- })
1396
- .then(result => resolve(result))
1397
- .catch(error => reject(error));
1398
- });
1399
- }
1400
- exports.updateItemTemplateFromDictionary = updateItemTemplateFromDictionary;
1401
- /**
1402
- * Updates the URL of an item.
1403
- *
1404
- * @param id AGOL id of item to update
1405
- * @param url URL to assign to item's base section
1406
- * @param authentication Credentials for the request
1407
- * @returns A promise that will resolve with the item id when the item has been updated or an AGO-style JSON failure
1408
- * response
1409
- */
1410
- function updateItemURL(id, url, authentication) {
1411
- const numAttempts = 3;
1412
- return _updateItemURL(id, url, authentication, numAttempts);
1413
- }
1414
- exports.updateItemURL = updateItemURL;
1415
- // ------------------------------------------------------------------------------------------------------------------ //
1416
- /**
1417
- * Adds a data section to an item.
1418
- *
1419
- * @param itemId Id of item to receive data file
1420
- * @param dataFile Data to be added
1421
- * @param authentication Credentials for the request
1422
- * @returns Promise reporting success or failure
1423
- * @private
1424
- */
1425
- function _addItemDataFile(itemId, dataFile, authentication) {
1426
- return new Promise((resolve, reject) => {
1427
- const addItemData = (data) => {
1428
- const addDataOptions = {
1429
- id: itemId,
1430
- data: data,
1431
- authentication: authentication
1432
- };
1433
- (0, arcgis_rest_portal_1.addItemData)(addDataOptions).then(resolve, reject);
1434
- };
1435
- // Item data has to be submitted as text or JSON for those file types
1436
- if (dataFile.type.startsWith("text/plain")) {
1437
- (0, generalHelpers_1.blobToText)(dataFile).then(addItemData, reject);
1438
- }
1439
- else if (dataFile.type === "application/json") {
1440
- (0, generalHelpers_1.blobToJson)(dataFile).then(addItemData, reject);
1441
- }
1442
- else {
1443
- addItemData(dataFile);
1444
- }
1445
- });
1446
- }
1447
- exports._addItemDataFile = _addItemDataFile;
1448
- /**
1449
- * Adds a metadata file to an item.
1450
- *
1451
- * @param itemId Id of item to receive data file
1452
- * @param metadataFile Metadata to be added
1453
- * @param authentication Credentials for the request
1454
- * @returns Promise reporting success or failure
1455
- * @private
1456
- */
1457
- function _addItemMetadataFile(itemId, metadataFile, authentication) {
1458
- return new Promise((resolve, reject) => {
1459
- const addMetadataOptions = {
1460
- item: {
1461
- id: itemId
1462
- },
1463
- params: {
1464
- // Pass metadata in via params because item property is serialized, which discards a blob
1465
- metadata: metadataFile
1466
- },
1467
- authentication: authentication
1468
- };
1469
- (0, arcgis_rest_portal_1.updateItem)(addMetadataOptions).then(resolve, reject);
1470
- });
1471
- }
1472
- exports._addItemMetadataFile = _addItemMetadataFile;
1473
- /**
1474
- * Accumulates the number of relationships in a collection of layers.
1475
- *
1476
- * @param List of layers to examine
1477
- * @returns The number of relationships
1478
- * @private
1479
- */
1480
- function _countRelationships(layers) {
1481
- const reducer = (accumulator, currentLayer) => accumulator +
1482
- (currentLayer.relationships ? currentLayer.relationships.length : 0);
1483
- return layers.reduce(reducer, 0);
1484
- }
1485
- exports._countRelationships = _countRelationships;
1486
- /**
1487
- * Gets the full definitions of the layers affiliated with a hosted service.
1488
- *
1489
- * @param serviceUrl URL to hosted service
1490
- * @param layerList List of layers at that service...must contain id
1491
- * @param authentication Credentials for the request
1492
- * @returns A promise that will resolve with a list of the layers from the admin api
1493
- * @private
1494
- */
1495
- function _getCreateServiceOptions(newItemTemplate, authentication, templateDictionary) {
1496
- return new Promise((resolve, reject) => {
1497
- const serviceInfo = newItemTemplate.properties;
1498
- const folderId = templateDictionary.folderId;
1499
- const isPortal = templateDictionary.isPortal;
1500
- const itemId = newItemTemplate.itemId;
1501
- (0, featureServiceHelpers_1.validateSpatialReferenceAndExtent)(serviceInfo, newItemTemplate, templateDictionary);
1502
- const fallbackExtent = _getFallbackExtent(serviceInfo, templateDictionary);
1503
- const params = {};
1504
- const itemInfo = {
1505
- title: newItemTemplate.item.title,
1506
- name: newItemTemplate.item.name
1507
- };
1508
- const _item = {
1509
- ...itemInfo,
1510
- preserveLayerIds: true
1511
- };
1512
- const createOptions = {
1513
- item: _item,
1514
- folderId,
1515
- params,
1516
- authentication: authentication
1517
- };
1518
- createOptions.item = !(0, trackingHelpers_1.isTrackingViewTemplate)(newItemTemplate) ?
1519
- _setItemProperties(createOptions.item, newItemTemplate, serviceInfo, params, isPortal) :
1520
- (0, trackingHelpers_1.setTrackingOptions)(newItemTemplate, createOptions, templateDictionary);
1521
- // project the portals extent to match that of the service
1522
- convertExtentWithFallback(templateDictionary.organization.defaultExtent, fallbackExtent, serviceInfo.service.spatialReference, templateDictionary.organization.helperServices.geometry.url, authentication).then(extent => {
1523
- templateDictionary[itemId].solutionExtent = extent;
1524
- (0, featureServiceHelpers_1.setDefaultSpatialReference)(templateDictionary, itemId, extent.spatialReference);
1525
- createOptions.item = (0, templatization_1.replaceInTemplate)(createOptions.item, templateDictionary);
1526
- createOptions.params = (0, templatization_1.replaceInTemplate)(createOptions.params, templateDictionary);
1527
- if (newItemTemplate.item.thumbnail) {
1528
- // Pass thumbnail file in via params because item property is serialized, which discards a blob
1529
- createOptions.params.thumbnail = newItemTemplate.item.thumbnail;
1530
- }
1531
- resolve(createOptions);
1532
- }, e => reject((0, generalHelpers_1.fail)(e)));
1533
- });
1534
- }
1535
- exports._getCreateServiceOptions = _getCreateServiceOptions;
1536
- /**
1537
- * When the services spatial reference does not match that of it's default extent
1538
- * use the out SRs default extent if it exists in the templateDictionary
1539
- * this should be set when adding a custom out wkid to the params before calling deploy
1540
- * this will help avoid situations where the orgs default extent and default world extent
1541
- * will not project successfully to the out SR
1542
- *
1543
- * @param serviceInfo the object that contains the spatial reference to evaluate
1544
- * @param templateDictionary the template dictionary
1545
- * @returns the extent to use as the fallback
1546
- * @private
1547
- */
1548
- function _getFallbackExtent(serviceInfo, templateDictionary) {
1549
- const serviceSR = serviceInfo.service.spatialReference;
1550
- const serviceInfoWkid = (0, generalHelpers_1.getProp)(serviceInfo, "defaultExtent.spatialReference.wkid");
1551
- const customDefaultExtent = (0, generalHelpers_1.getProp)(templateDictionary, "params.defaultExtent");
1552
- return serviceInfoWkid && serviceInfoWkid === serviceSR.wkid
1553
- ? serviceInfo.defaultExtent
1554
- : customDefaultExtent
1555
- ? customDefaultExtent
1556
- : serviceInfo.defaultExtent;
1557
- }
1558
- exports._getFallbackExtent = _getFallbackExtent;
1559
- /**
1560
- * Add relationships to all layers in one call to retain fully functioning composite relationships
1561
- *
1562
- * @param args The IPostProcessArgs for the request(s)
1563
- * @returns Any relationships that should be updated for the service
1564
- * @private
1565
- */
1566
- function _getRelationshipUpdates(args) {
1567
- const rels = {
1568
- layers: []
1569
- };
1570
- Object.keys(args.objects).forEach((k) => {
1571
- const obj = args.objects[k];
1572
- /* istanbul ignore else */
1573
- if (obj.relationships && obj.relationships.length > 0) {
1574
- rels.layers.push({
1575
- id: obj.id,
1576
- relationships: obj.relationships
1577
- });
1578
- }
1579
- (0, generalHelpers_1.deleteProp)(obj, "relationships");
1580
- });
1581
- return rels;
1582
- }
1583
- exports._getRelationshipUpdates = _getRelationshipUpdates;
1584
- /**
1585
- * Get the stored contingent values and structure them to be added to the services layers.
1586
- *
1587
- * @param args The IPostProcessArgs for the request(s)
1588
- * @returns Any contingent values that should be added to the service.
1589
- * @private
1590
- */
1591
- function _getContingentValuesUpdates(args) {
1592
- const contingentValues = [];
1593
- Object.keys(args.objects).forEach((k) => {
1594
- const obj = args.objects[k];
1595
- /* istanbul ignore else */
1596
- if (obj.contingentValues) {
1597
- contingentValues.push({
1598
- id: obj.id,
1599
- contingentValues: obj.contingentValues
1600
- });
1601
- }
1602
- (0, generalHelpers_1.deleteProp)(obj, "contingentValues");
1603
- });
1604
- return contingentValues;
1605
- }
1606
- exports._getContingentValuesUpdates = _getContingentValuesUpdates;
1607
- /**
1608
- * Get refresh, add, update, or delete definition info
1609
- *
1610
- * @param url the base admin url for the service
1611
- * @param id the id of the layer
1612
- * @param obj parameters for the request
1613
- * @param args various arguments to help support the request
1614
- * @param type type of update the request will handle
1615
- * @returns IUpdate that has the request url and arguments
1616
- * @private
1617
- */
1618
- function _getUpdate(url, id, obj, args, type) {
1619
- const ops = {
1620
- delete: {
1621
- url: (0, generalHelpers_1.checkUrlPathTermination)(url) + id + "/deleteFromDefinition",
1622
- params: {
1623
- deleteFromDefinition: {
1624
- fields: obj && obj.hasOwnProperty("deleteFields") ? obj.deleteFields : []
1625
- }
1626
- }
1627
- },
1628
- update: {
1629
- url: (0, generalHelpers_1.checkUrlPathTermination)(url) +
1630
- (id ? `${id}/updateDefinition` : "updateDefinition"),
1631
- params: {
1632
- updateDefinition: obj
1633
- }
1634
- },
1635
- add: {
1636
- url: (0, generalHelpers_1.checkUrlPathTermination)(url) + "addToDefinition",
1637
- params: {
1638
- addToDefinition: obj
1639
- }
1640
- },
1641
- refresh: {
1642
- url: (0, generalHelpers_1.checkUrlPathTermination)(url) + "refresh",
1643
- params: {
1644
- f: "json"
1645
- }
1646
- }
1647
- };
1648
- return {
1649
- url: ops[type].url,
1650
- params: ops[type].params,
1651
- args: args
1652
- };
1653
- }
1654
- exports._getUpdate = _getUpdate;
1655
- /**
1656
- * Changes just the domain part of a URL to lowercase.
1657
- *
1658
- * @param url URL to modify
1659
- * @return Adjusted URL
1660
- * @see From `getServerRootUrl` in arcgis-rest-js' ArcGISIdentityManager.ts
1661
- * @private
1662
- */
1663
- function _lowercaseDomain(url) {
1664
- if (!url) {
1665
- return url;
1666
- }
1667
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1668
- const [_, protocol, domainAndPath] = url.match(/(https?:\/\/)(.+)/);
1669
- const [domain, ...path] = domainAndPath.split("/");
1670
- // Only the domain is lowercased because in some cases an org id might be
1671
- // in the path which cannot be lowercased.
1672
- return `${protocol}${domain.toLowerCase()}/${path.join("/")}`;
1673
- }
1674
- exports._lowercaseDomain = _lowercaseDomain;
1675
- /**
1676
- * Checks the two main parts of an item for unresolved variables and reports any found.
1677
- *
1678
- * @param base Item's base section
1679
- * @param data Item's data section
1680
- * @private
1681
- */
1682
- function _reportVariablesInItem(itemId, itemType, base, data) {
1683
- const getUnresolved = (v) => {
1684
- return JSON.stringify(v).match(/{{.+?}}/gim);
1685
- };
1686
- // Provide feedback about any remaining unresolved variables
1687
- /* istanbul ignore else */
1688
- if (base && (0, templatization_1.hasUnresolvedVariables)(base)) {
1689
- console.log(itemId +
1690
- " (" +
1691
- itemType +
1692
- ") contains variables in base: " +
1693
- JSON.stringify(getUnresolved(base)));
1694
- }
1695
- /* istanbul ignore else */
1696
- if (data && (0, templatization_1.hasUnresolvedVariables)(data)) {
1697
- console.log(itemId +
1698
- " (" +
1699
- itemType +
1700
- ") contains variables in data: " +
1701
- JSON.stringify(getUnresolved(data)));
1702
- }
1703
- }
1704
- exports._reportVariablesInItem = _reportVariablesInItem;
1705
- /**
1706
- * Updates a feature service item.
1707
- *
1708
- * @param item Item to update
1709
- * @param itemTemplate item template for the new item
1710
- * @param serviceInfo Service information
1711
- * @param params arcgis-rest-js params to update
1712
- * @param isPortal Is the service hosted in a portal?
1713
- * @returns Updated item
1714
- * @private
1715
- */
1716
- function _setItemProperties(item, itemTemplate, serviceInfo, params, isPortal) {
1717
- // Set the capabilities
1718
- const portalCapabilities = [
1719
- "Create",
1720
- "Query",
1721
- "Editing",
1722
- "Update",
1723
- "Delete",
1724
- "Uploads",
1725
- "Sync",
1726
- "Extract"
1727
- ];
1728
- const capabilities = (0, generalHelpers_1.getProp)(serviceInfo, "service.capabilities") || (isPortal ? "" : []);
1729
- item.capabilities = isPortal
1730
- ? capabilities
1731
- .split(",")
1732
- .filter((c) => portalCapabilities.indexOf(c) > -1)
1733
- .join(",")
1734
- : capabilities;
1735
- if (serviceInfo.service.capabilities) {
1736
- serviceInfo.service.capabilities = item.capabilities;
1737
- }
1738
- // Handle index update for any pre-published solution items that
1739
- // have non-unique indexes on relationship key fields
1740
- _updateIndexesForRelationshipKeyFields(serviceInfo);
1741
- // set create options item properties
1742
- const keyProperties = [
1743
- "isView",
1744
- "sourceSchemaChangesAllowed",
1745
- "isUpdatableView",
1746
- "capabilities",
1747
- "isMultiServicesView"
1748
- ];
1749
- const deleteKeys = ["layers", "tables"];
1750
- /* istanbul ignore else */
1751
- if (isPortal) {
1752
- // removed for issue #423 causing FS to fail to create
1753
- deleteKeys.push("adminServiceInfo");
1754
- }
1755
- const itemKeys = Object.keys(item);
1756
- const serviceKeys = Object.keys(serviceInfo.service);
1757
- serviceKeys.forEach(k => {
1758
- /* istanbul ignore else */
1759
- if (itemKeys.indexOf(k) === -1 && deleteKeys.indexOf(k) < 0) {
1760
- item[k] = serviceInfo.service[k];
1761
- // These need to be included via params otherwise...
1762
- // addToDef calls fail when adding adminLayerInfo
1763
- /* istanbul ignore else */
1764
- if (serviceInfo.service.isView && keyProperties.indexOf(k) > -1) {
1765
- params[k] = serviceInfo.service[k];
1766
- }
1767
- }
1768
- });
1769
- // Enable editor tracking on layer with related tables is not supported.
1770
- /* istanbul ignore else */
1771
- if (item.isMultiServicesView &&
1772
- (0, generalHelpers_1.getProp)(item, "editorTrackingInfo.enableEditorTracking")) {
1773
- item.editorTrackingInfo.enableEditorTracking = false;
1774
- params["editorTrackingInfo"] = item.editorTrackingInfo;
1775
- }
1776
- /* istanbul ignore else */
1777
- if (isPortal) {
1778
- // portal will fail when initialExtent is defined but null
1779
- // removed for issue #449 causing FS to fail to create on portal
1780
- /* istanbul ignore else */
1781
- if (Object.keys(item).indexOf("initialExtent") > -1 &&
1782
- !item.initialExtent) {
1783
- (0, generalHelpers_1.deleteProp)(item, "initialExtent");
1784
- }
1785
- }
1786
- return item;
1787
- }
1788
- exports._setItemProperties = _setItemProperties;
1789
- /**
1790
- * Set isUnique as true for indexes that reference origin relationship keyFields.
1791
- *
1792
- * @param serviceInfo Service information
1793
- * @private
1794
- */
1795
- function _updateIndexesForRelationshipKeyFields(serviceInfo) {
1796
- const layersAndTables = (serviceInfo.layers || []).concat(serviceInfo.tables || []);
1797
- layersAndTables.forEach(item => {
1798
- const relationships = item.relationships;
1799
- const indexes = item.indexes;
1800
- /* istanbul ignore else */
1801
- if (relationships &&
1802
- relationships.length > 0 &&
1803
- indexes &&
1804
- indexes.length > 0) {
1805
- const keyFields = relationships.reduce((acc, v) => {
1806
- /* istanbul ignore else */
1807
- if (v.role === "esriRelRoleOrigin" &&
1808
- v.keyField &&
1809
- acc.indexOf(v.keyField) < 0) {
1810
- acc.push(v.keyField);
1811
- }
1812
- return acc;
1813
- }, []);
1814
- indexes.map(i => {
1815
- /* istanbul ignore else */
1816
- if (keyFields.some(k => {
1817
- const regEx = new RegExp(`\\b${k}\\b`);
1818
- return regEx.test(i.fields);
1819
- })) {
1820
- i.isUnique = true;
1821
- }
1822
- return i;
1823
- });
1824
- }
1825
- });
1826
- }
1827
- exports._updateIndexesForRelationshipKeyFields = _updateIndexesForRelationshipKeyFields;
1828
- /**
1829
- * Updates the URL of an item.
1830
- *
1831
- * @param id AGOL id of item to update
1832
- * @param url URL to assign to item's base section
1833
- * @param authentication Credentials for the request
1834
- * @param numAttempts Number of times to try to set the URL if AGO says that it updated the URL, but really didn't
1835
- * @returns A promise that will resolve with the item id when the item has been updated or an AGO-style JSON failure
1836
- * response
1837
- * @private
1838
- */
1839
- function _updateItemURL(id, url, authentication, numAttempts = 1) {
1840
- // Introduce a lag because AGO update appears to choke with rapid subsequent calls
1841
- const msLag = 1000;
1842
- return new Promise((resolve, reject) => {
1843
- // Update the item's URL
1844
- const options = { item: { id, url }, authentication: authentication };
1845
- (0, arcgis_rest_portal_1.updateItem)(options).then(result => {
1846
- if (!result.success) {
1847
- reject((0, generalHelpers_1.fail)(result));
1848
- }
1849
- else {
1850
- // Get the item to see if the URL really changed; we'll delay a bit before testing because AGO
1851
- // has a timing problem with URL updates
1852
- setTimeout(() => {
1853
- (0, arcgis_rest_portal_1.getItem)(id, { authentication: authentication }).then(item => {
1854
- const iBrace = item.url.indexOf("{");
1855
- if (iBrace > -1) {
1856
- console.warn(id + " has template variable: " + item.url.substr(iBrace));
1857
- }
1858
- if (url === item.url) {
1859
- resolve(id);
1860
- }
1861
- else {
1862
- // If it fails, try again if we have sufficient attempts remaining
1863
- const errorMsg = "URL not updated for " +
1864
- item.type +
1865
- " " +
1866
- item.id +
1867
- ": " +
1868
- item.url +
1869
- " (" +
1870
- numAttempts +
1871
- ")";
1872
- if (--numAttempts > 0) {
1873
- _updateItemURL(id, url, authentication, numAttempts).then(resolve, reject);
1874
- }
1875
- else {
1876
- console.error(id + ": " + errorMsg + "; FAILED");
1877
- reject(errorMsg);
1878
- }
1879
- }
1880
- }, e => reject((0, generalHelpers_1.fail)(e)));
1881
- }, msLag);
1882
- }
1883
- }, e => reject((0, generalHelpers_1.fail)(e)));
1884
- });
1885
- }
1886
- exports._updateItemURL = _updateItemURL;
1887
- //# sourceMappingURL=restHelpers.js.map