@esri/solution-common 1.1.2 → 1.2.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.
- package/dist/esm/completeItem.js +6 -7
- package/dist/esm/completeItem.js.map +1 -1
- package/dist/esm/create-hub-request-options.d.ts +4 -4
- package/dist/esm/create-hub-request-options.js +9 -12
- package/dist/esm/create-hub-request-options.js.map +1 -1
- package/dist/esm/deleteHelpers/deleteEmptyGroups.js +2 -2
- package/dist/esm/deleteHelpers/deleteEmptyGroups.js.map +1 -1
- package/dist/esm/deleteHelpers/deleteGroupIfEmpty.js +15 -15
- package/dist/esm/deleteHelpers/deleteGroupIfEmpty.js.map +1 -1
- package/dist/esm/deleteHelpers/deleteSolutionContents.js +20 -22
- package/dist/esm/deleteHelpers/deleteSolutionContents.js.map +1 -1
- package/dist/esm/deleteHelpers/deleteSolutionFolder.js +10 -10
- package/dist/esm/deleteHelpers/deleteSolutionFolder.js.map +1 -1
- package/dist/esm/deleteHelpers/deleteSolutionItem.js +4 -4
- package/dist/esm/deleteHelpers/deleteSolutionItem.js.map +1 -1
- package/dist/esm/deleteHelpers/reconstructBuildOrderIds.js +1 -1
- package/dist/esm/deleteHelpers/reconstructBuildOrderIds.js.map +1 -1
- package/dist/esm/deleteHelpers/removeItems.js +20 -29
- package/dist/esm/deleteHelpers/removeItems.js.map +1 -1
- package/dist/esm/deleteHelpers/reportProgress.js +3 -6
- package/dist/esm/deleteHelpers/reportProgress.js.map +1 -1
- package/dist/esm/deleteSolution.js +10 -12
- package/dist/esm/deleteSolution.js.map +1 -1
- package/dist/esm/dependencies.js +27 -19
- package/dist/esm/dependencies.js.map +1 -1
- package/dist/esm/featureServiceHelpers.d.ts +6 -0
- package/dist/esm/featureServiceHelpers.js +530 -500
- package/dist/esm/featureServiceHelpers.js.map +1 -1
- package/dist/esm/generalHelpers.js +72 -76
- package/dist/esm/generalHelpers.js.map +1 -1
- package/dist/esm/get-subscription-info.js +5 -3
- package/dist/esm/get-subscription-info.js.map +1 -1
- package/dist/esm/getDeletableSolutionInfo.js +6 -10
- package/dist/esm/getDeletableSolutionInfo.js.map +1 -1
- package/dist/esm/getSolutionSummary.js +15 -19
- package/dist/esm/getSolutionSummary.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces.d.ts +39 -1
- package/dist/esm/interfaces.js +3 -3
- package/dist/esm/interfaces.js.map +1 -1
- package/dist/esm/libConnectors.js +5 -7
- package/dist/esm/libConnectors.js.map +1 -1
- package/dist/esm/migrations/apply-schema.js +3 -3
- package/dist/esm/migrations/apply-schema.js.map +1 -1
- package/dist/esm/migrations/is-legacy-solution.js +2 -2
- package/dist/esm/migrations/is-legacy-solution.js.map +1 -1
- package/dist/esm/migrations/upgrade-three-dot-one.js +3 -3
- package/dist/esm/migrations/upgrade-three-dot-one.js.map +1 -1
- package/dist/esm/migrations/upgrade-three-dot-zero.js +1 -1
- package/dist/esm/migrations/upgrade-three-dot-zero.js.map +1 -1
- package/dist/esm/migrations/upgrade-two-dot-five.js +17 -8
- package/dist/esm/migrations/upgrade-two-dot-five.js.map +1 -1
- package/dist/esm/migrations/upgrade-two-dot-four.js +12 -12
- package/dist/esm/migrations/upgrade-two-dot-four.js.map +1 -1
- package/dist/esm/migrations/upgrade-two-dot-one.js +1 -1
- package/dist/esm/migrations/upgrade-two-dot-one.js.map +1 -1
- package/dist/esm/migrations/upgrade-two-dot-seven.js +1 -1
- package/dist/esm/migrations/upgrade-two-dot-seven.js.map +1 -1
- package/dist/esm/migrations/upgrade-two-dot-six.js +9 -12
- package/dist/esm/migrations/upgrade-two-dot-six.js.map +1 -1
- package/dist/esm/migrations/upgrade-two-dot-three.js +3 -3
- package/dist/esm/migrations/upgrade-two-dot-three.js.map +1 -1
- package/dist/esm/migrations/upgrade-two-dot-two.js +3 -3
- package/dist/esm/migrations/upgrade-two-dot-two.js.map +1 -1
- package/dist/esm/migrations/upgrade-two-dot-zero.js +8 -9
- package/dist/esm/migrations/upgrade-two-dot-zero.js.map +1 -1
- package/dist/esm/migrator.js +5 -7
- package/dist/esm/migrator.js.map +1 -1
- package/dist/esm/polyfills.js +5 -5
- package/dist/esm/polyfills.js.map +1 -1
- package/dist/esm/resourceHelpers.js +54 -57
- package/dist/esm/resourceHelpers.js.map +1 -1
- package/dist/esm/resources/add-resource-from-blob.js +2 -2
- package/dist/esm/resources/add-resource-from-blob.js.map +1 -1
- package/dist/esm/resources/addMetadataFromBlob.js +1 -1
- package/dist/esm/resources/addMetadataFromBlob.js.map +1 -1
- package/dist/esm/resources/convert-item-resource-to-storage-resource.js +6 -7
- package/dist/esm/resources/convert-item-resource-to-storage-resource.js.map +1 -1
- package/dist/esm/resources/convert-storage-resource-to-item-resource.js +8 -9
- package/dist/esm/resources/convert-storage-resource-to-item-resource.js.map +1 -1
- package/dist/esm/resources/copyAssociatedFiles.js +44 -53
- package/dist/esm/resources/copyAssociatedFiles.js.map +1 -1
- package/dist/esm/resources/copyDataIntoItem.js +5 -11
- package/dist/esm/resources/copyDataIntoItem.js.map +1 -1
- package/dist/esm/resources/copyMetadataIntoItem.js +4 -10
- package/dist/esm/resources/copyMetadataIntoItem.js.map +1 -1
- package/dist/esm/resources/copyResourceIntoZip.js +5 -7
- package/dist/esm/resources/copyResourceIntoZip.js.map +1 -1
- package/dist/esm/resources/copyZipIntoItem.js +5 -9
- package/dist/esm/resources/copyZipIntoItem.js.map +1 -1
- package/dist/esm/resources/createCopyResults.js +5 -2
- package/dist/esm/resources/createCopyResults.js.map +1 -1
- package/dist/esm/resources/get-blob.js +7 -5
- package/dist/esm/resources/get-blob.js.map +1 -1
- package/dist/esm/resources/getItemResourcesFilesFromPaths.js +7 -7
- package/dist/esm/resources/getItemResourcesFilesFromPaths.js.map +1 -1
- package/dist/esm/resources/getItemResourcesPaths.js +7 -8
- package/dist/esm/resources/getItemResourcesPaths.js.map +1 -1
- package/dist/esm/resources/transform-resource-paths-to-solution-resources.js +8 -9
- package/dist/esm/resources/transform-resource-paths-to-solution-resources.js.map +1 -1
- package/dist/esm/restHelpers.d.ts +65 -5
- package/dist/esm/restHelpers.js +422 -276
- package/dist/esm/restHelpers.js.map +1 -1
- package/dist/esm/restHelpersGet.js +102 -111
- package/dist/esm/restHelpersGet.js.map +1 -1
- package/dist/esm/sharing/share-item-to-groups.d.ts +2 -1
- package/dist/esm/sharing/share-item-to-groups.js +12 -6
- package/dist/esm/sharing/share-item-to-groups.js.map +1 -1
- package/dist/esm/templatization.js +64 -40
- package/dist/esm/templatization.js.map +1 -1
- package/dist/esm/trackingHelpers.d.ts +116 -0
- package/dist/esm/trackingHelpers.js +205 -0
- package/dist/esm/trackingHelpers.js.map +1 -0
- package/dist/esm/velocityHelpers.d.ts +2 -0
- package/dist/esm/velocityHelpers.js +30 -12
- package/dist/esm/velocityHelpers.js.map +1 -1
- package/dist/esm/workforceHelpers.d.ts +11 -0
- package/dist/esm/workforceHelpers.js +208 -180
- package/dist/esm/workforceHelpers.js.map +1 -1
- package/dist/node/completeItem.js +8 -9
- package/dist/node/completeItem.js.map +1 -1
- package/dist/node/create-hub-request-options.d.ts +4 -4
- package/dist/node/create-hub-request-options.js +11 -14
- package/dist/node/create-hub-request-options.js.map +1 -1
- package/dist/node/deleteHelpers/deleteEmptyGroups.js +3 -3
- package/dist/node/deleteHelpers/deleteEmptyGroups.js.map +1 -1
- package/dist/node/deleteHelpers/deleteGroupIfEmpty.js +16 -16
- package/dist/node/deleteHelpers/deleteGroupIfEmpty.js.map +1 -1
- package/dist/node/deleteHelpers/deleteSolutionContents.js +26 -28
- package/dist/node/deleteHelpers/deleteSolutionContents.js.map +1 -1
- package/dist/node/deleteHelpers/deleteSolutionFolder.js +11 -11
- package/dist/node/deleteHelpers/deleteSolutionFolder.js.map +1 -1
- package/dist/node/deleteHelpers/deleteSolutionItem.js +6 -6
- package/dist/node/deleteHelpers/deleteSolutionItem.js.map +1 -1
- package/dist/node/deleteHelpers/index.js +1 -1
- package/dist/node/deleteHelpers/reconstructBuildOrderIds.js +2 -2
- package/dist/node/deleteHelpers/reconstructBuildOrderIds.js.map +1 -1
- package/dist/node/deleteHelpers/removeItems.js +26 -35
- package/dist/node/deleteHelpers/removeItems.js.map +1 -1
- package/dist/node/deleteHelpers/reportProgress.js +4 -7
- package/dist/node/deleteHelpers/reportProgress.js.map +1 -1
- package/dist/node/deleteSolution.js +12 -14
- package/dist/node/deleteSolution.js.map +1 -1
- package/dist/node/dependencies.js +29 -21
- package/dist/node/dependencies.js.map +1 -1
- package/dist/node/featureServiceHelpers.d.ts +6 -0
- package/dist/node/featureServiceHelpers.js +535 -504
- package/dist/node/featureServiceHelpers.js.map +1 -1
- package/dist/node/generalHelpers.js +75 -79
- package/dist/node/generalHelpers.js.map +1 -1
- package/dist/node/get-subscription-info.js +7 -5
- package/dist/node/get-subscription-info.js.map +1 -1
- package/dist/node/getDeletableSolutionInfo.js +8 -12
- package/dist/node/getDeletableSolutionInfo.js.map +1 -1
- package/dist/node/getSolutionSummary.js +19 -23
- package/dist/node/getSolutionSummary.js.map +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +2 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/interfaces.d.ts +39 -1
- package/dist/node/interfaces.js.map +1 -1
- package/dist/node/libConnectors.js +8 -10
- package/dist/node/libConnectors.js.map +1 -1
- package/dist/node/migrations/apply-schema.js +4 -4
- package/dist/node/migrations/apply-schema.js.map +1 -1
- package/dist/node/migrations/is-legacy-solution.js +3 -3
- package/dist/node/migrations/is-legacy-solution.js.map +1 -1
- package/dist/node/migrations/upgrade-three-dot-one.js +5 -5
- package/dist/node/migrations/upgrade-three-dot-one.js.map +1 -1
- package/dist/node/migrations/upgrade-three-dot-zero.js +2 -2
- package/dist/node/migrations/upgrade-three-dot-zero.js.map +1 -1
- package/dist/node/migrations/upgrade-two-dot-five.js +18 -9
- package/dist/node/migrations/upgrade-two-dot-five.js.map +1 -1
- package/dist/node/migrations/upgrade-two-dot-four.js +13 -13
- package/dist/node/migrations/upgrade-two-dot-four.js.map +1 -1
- package/dist/node/migrations/upgrade-two-dot-one.js +2 -2
- package/dist/node/migrations/upgrade-two-dot-one.js.map +1 -1
- package/dist/node/migrations/upgrade-two-dot-seven.js +2 -2
- package/dist/node/migrations/upgrade-two-dot-seven.js.map +1 -1
- package/dist/node/migrations/upgrade-two-dot-six.js +10 -13
- package/dist/node/migrations/upgrade-two-dot-six.js.map +1 -1
- package/dist/node/migrations/upgrade-two-dot-three.js +5 -5
- package/dist/node/migrations/upgrade-two-dot-three.js.map +1 -1
- package/dist/node/migrations/upgrade-two-dot-two.js +5 -5
- package/dist/node/migrations/upgrade-two-dot-two.js.map +1 -1
- package/dist/node/migrations/upgrade-two-dot-zero.js +9 -10
- package/dist/node/migrations/upgrade-two-dot-zero.js.map +1 -1
- package/dist/node/migrator.js +16 -18
- package/dist/node/migrator.js.map +1 -1
- package/dist/node/polyfills.js +5 -5
- package/dist/node/polyfills.js.map +1 -1
- package/dist/node/resourceHelpers.js +62 -65
- package/dist/node/resourceHelpers.js.map +1 -1
- package/dist/node/resources/add-resource-from-blob.js +4 -4
- package/dist/node/resources/add-resource-from-blob.js.map +1 -1
- package/dist/node/resources/addMetadataFromBlob.js +2 -2
- package/dist/node/resources/addMetadataFromBlob.js.map +1 -1
- package/dist/node/resources/convert-item-resource-to-storage-resource.js +6 -7
- package/dist/node/resources/convert-item-resource-to-storage-resource.js.map +1 -1
- package/dist/node/resources/convert-storage-resource-to-item-resource.js +9 -10
- package/dist/node/resources/convert-storage-resource-to-item-resource.js.map +1 -1
- package/dist/node/resources/copyAssociatedFiles.js +52 -61
- package/dist/node/resources/copyAssociatedFiles.js.map +1 -1
- package/dist/node/resources/copyDataIntoItem.js +9 -15
- package/dist/node/resources/copyDataIntoItem.js.map +1 -1
- package/dist/node/resources/copyMetadataIntoItem.js +7 -13
- package/dist/node/resources/copyMetadataIntoItem.js.map +1 -1
- package/dist/node/resources/copyResourceIntoZip.js +7 -9
- package/dist/node/resources/copyResourceIntoZip.js.map +1 -1
- package/dist/node/resources/copyZipIntoItem.js +8 -12
- package/dist/node/resources/copyZipIntoItem.js.map +1 -1
- package/dist/node/resources/createCopyResults.js +5 -2
- package/dist/node/resources/createCopyResults.js.map +1 -1
- package/dist/node/resources/get-blob.js +8 -6
- package/dist/node/resources/get-blob.js.map +1 -1
- package/dist/node/resources/getItemResourcesFilesFromPaths.js +8 -8
- package/dist/node/resources/getItemResourcesFilesFromPaths.js.map +1 -1
- package/dist/node/resources/getItemResourcesPaths.js +9 -10
- package/dist/node/resources/getItemResourcesPaths.js.map +1 -1
- package/dist/node/resources/index.js +1 -1
- package/dist/node/resources/transform-resource-paths-to-solution-resources.js +10 -11
- package/dist/node/resources/transform-resource-paths-to-solution-resources.js.map +1 -1
- package/dist/node/restHelpers.d.ts +65 -5
- package/dist/node/restHelpers.js +437 -285
- package/dist/node/restHelpers.js.map +1 -1
- package/dist/node/restHelpersGet.js +107 -116
- package/dist/node/restHelpersGet.js.map +1 -1
- package/dist/node/sharing/index.js +1 -1
- package/dist/node/sharing/share-item-to-groups.d.ts +2 -1
- package/dist/node/sharing/share-item-to-groups.js +13 -7
- package/dist/node/sharing/share-item-to-groups.js.map +1 -1
- package/dist/node/templatization.js +61 -37
- package/dist/node/templatization.js.map +1 -1
- package/dist/node/trackingHelpers.d.ts +116 -0
- package/dist/node/trackingHelpers.js +217 -0
- package/dist/node/trackingHelpers.js.map +1 -0
- package/dist/node/velocityHelpers.d.ts +2 -0
- package/dist/node/velocityHelpers.js +33 -15
- package/dist/node/velocityHelpers.js.map +1 -1
- package/dist/node/workforceHelpers.d.ts +11 -0
- package/dist/node/workforceHelpers.js +214 -185
- package/dist/node/workforceHelpers.js.map +1 -1
- package/dist/umd/common.umd.js +14830 -14466
- package/dist/umd/common.umd.js.map +1 -1
- package/dist/umd/common.umd.min.js +3 -3
- package/dist/umd/common.umd.min.js.map +1 -1
- package/dist/umd/create-hub-request-options.d.ts +4 -4
- package/dist/umd/featureServiceHelpers.d.ts +6 -0
- package/dist/umd/index.d.ts +1 -0
- package/dist/umd/interfaces.d.ts +39 -1
- package/dist/umd/restHelpers.d.ts +65 -5
- package/dist/umd/sharing/share-item-to-groups.d.ts +2 -1
- package/dist/umd/trackingHelpers.d.ts +116 -0
- package/dist/umd/velocityHelpers.d.ts +2 -0
- package/dist/umd/workforceHelpers.d.ts +11 -0
- package/package.json +24 -24
package/dist/esm/restHelpers.js
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { __assign, __read } from "tslib";
|
|
17
16
|
/**
|
|
18
17
|
* Provides common functions involving the arcgis-rest-js library.
|
|
19
18
|
*
|
|
@@ -21,16 +20,27 @@ import { __assign, __read } from "tslib";
|
|
|
21
20
|
*/
|
|
22
21
|
import { removeLayerOptimization, setDefaultSpatialReference, validateSpatialReferenceAndExtent } from "./featureServiceHelpers";
|
|
23
22
|
import { appendQueryParam, blobToJson, blobToText, checkUrlPathTermination, deleteProp, deleteProps, fail, getProp, getUniqueTitle, setCreateProp } from "./generalHelpers";
|
|
23
|
+
import { UserSession } from "./interfaces";
|
|
24
24
|
import { createZip } from "./libConnectors";
|
|
25
25
|
import { getItemBase, getItemDataAsJson } from "./restHelpersGet";
|
|
26
|
-
import { addItemData as portalAddItemData, addItemRelationship, addItemResource, createFolder, createGroup, createItemInFolder, getItem, removeFolder as portalRemoveFolder, removeGroup as portalRemoveGroup, removeItem as portalRemoveItem, searchGroupContent, searchGroups as portalSearchGroups, searchItems as portalSearchItems, setItemAccess, shareItemWithGroup, updateItem as portalUpdateItem } from "@esri/arcgis-rest-portal";
|
|
26
|
+
import { addItemData as portalAddItemData, addItemRelationship, addItemResource, createFolder, createGroup, createItemInFolder, getItem, removeFolder as portalRemoveFolder, removeGroup as portalRemoveGroup, removeGroupUsers as portalRemoveGroupUsers, removeItem as portalRemoveItem, searchGroupContent, searchGroups as portalSearchGroups, searchItems as portalSearchItems, setItemAccess, shareItemWithGroup, updateItem as portalUpdateItem } from "@esri/arcgis-rest-portal";
|
|
27
27
|
import { request } from "@esri/arcgis-rest-request";
|
|
28
28
|
import { addToServiceDefinition as svcAdminAddToServiceDefinition, createFeatureService as svcAdminCreateFeatureService } from "@esri/arcgis-rest-service-admin";
|
|
29
29
|
import { getWorkforceDependencies, isWorkforceProject, getWorkforceServiceInfo } from "./workforceHelpers";
|
|
30
30
|
import { hasUnresolvedVariables, replaceInTemplate } from "./templatization";
|
|
31
|
+
import { isTrackingViewTemplate, setTrackingOptions } from "./trackingHelpers";
|
|
31
32
|
// ------------------------------------------------------------------------------------------------------------------ //
|
|
32
33
|
export { request as rest_request } from "@esri/arcgis-rest-request";
|
|
33
34
|
// ------------------------------------------------------------------------------------------------------------------ //
|
|
35
|
+
/**
|
|
36
|
+
* Creates a UserSession via a function so that the global arcgisSolution variable can access authentication.
|
|
37
|
+
*
|
|
38
|
+
* @param options See https://esri.github.io/arcgis-rest-js/api/auth/IUserSessionOptions/
|
|
39
|
+
* @return UserSession
|
|
40
|
+
*/
|
|
41
|
+
export function getUserSession(options = {}) {
|
|
42
|
+
return new UserSession(options);
|
|
43
|
+
}
|
|
34
44
|
/**
|
|
35
45
|
* Searches for items matching a query and that the caller has access to.
|
|
36
46
|
*
|
|
@@ -51,19 +61,19 @@ export function searchItems(search) {
|
|
|
51
61
|
* @return A Promise to add item resources.
|
|
52
62
|
*/
|
|
53
63
|
export function addForwardItemRelationship(originItemId, destinationItemId, relationshipType, authentication) {
|
|
54
|
-
return new Promise(
|
|
55
|
-
|
|
56
|
-
originItemId
|
|
57
|
-
destinationItemId
|
|
58
|
-
relationshipType
|
|
59
|
-
authentication
|
|
64
|
+
return new Promise(resolve => {
|
|
65
|
+
const requestOptions = {
|
|
66
|
+
originItemId,
|
|
67
|
+
destinationItemId,
|
|
68
|
+
relationshipType,
|
|
69
|
+
authentication
|
|
60
70
|
};
|
|
61
|
-
addItemRelationship(requestOptions).then(
|
|
71
|
+
addItemRelationship(requestOptions).then(response => {
|
|
62
72
|
resolve({
|
|
63
73
|
success: response.success,
|
|
64
74
|
itemId: originItemId
|
|
65
75
|
});
|
|
66
|
-
},
|
|
76
|
+
}, () => {
|
|
67
77
|
resolve({
|
|
68
78
|
success: false,
|
|
69
79
|
itemId: originItemId
|
|
@@ -80,18 +90,16 @@ export function addForwardItemRelationship(originItemId, destinationItemId, rela
|
|
|
80
90
|
* @return A Promise to add item resources.
|
|
81
91
|
*/
|
|
82
92
|
export function addForwardItemRelationships(originItemId, destinationRelationships, authentication) {
|
|
83
|
-
return new Promise(
|
|
93
|
+
return new Promise(resolve => {
|
|
84
94
|
// Set up relationships using updated relationship information
|
|
85
|
-
|
|
86
|
-
destinationRelationships.forEach(
|
|
87
|
-
relationship.relatedItemIds.forEach(
|
|
95
|
+
const relationshipPromises = new Array();
|
|
96
|
+
destinationRelationships.forEach(relationship => {
|
|
97
|
+
relationship.relatedItemIds.forEach(relatedItemId => {
|
|
88
98
|
relationshipPromises.push(addForwardItemRelationship(originItemId, relatedItemId, relationship.relationshipType, authentication));
|
|
89
99
|
});
|
|
90
100
|
});
|
|
91
101
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
92
|
-
Promise.all(relationshipPromises).then(
|
|
93
|
-
return resolve(responses);
|
|
94
|
-
});
|
|
102
|
+
Promise.all(relationshipPromises).then((responses) => resolve(responses));
|
|
95
103
|
});
|
|
96
104
|
}
|
|
97
105
|
/**
|
|
@@ -103,18 +111,18 @@ export function addForwardItemRelationships(originItemId, destinationRelationshi
|
|
|
103
111
|
* unless either the URL doesn't exist or the token can't be generated
|
|
104
112
|
*/
|
|
105
113
|
export function addTokenToUrl(url, authentication) {
|
|
106
|
-
return new Promise(
|
|
114
|
+
return new Promise(resolve => {
|
|
107
115
|
if (!url || !authentication) {
|
|
108
116
|
resolve(url);
|
|
109
117
|
}
|
|
110
118
|
else {
|
|
111
|
-
authentication.getToken(url).then(
|
|
119
|
+
authentication.getToken(url).then(token => {
|
|
112
120
|
/* istanbul ignore else */
|
|
113
121
|
if (token) {
|
|
114
122
|
url = appendQueryParam(url, "token=" + token);
|
|
115
123
|
}
|
|
116
124
|
resolve(url);
|
|
117
|
-
},
|
|
125
|
+
}, () => resolve(url));
|
|
118
126
|
}
|
|
119
127
|
});
|
|
120
128
|
}
|
|
@@ -131,19 +139,17 @@ export function addTokenToUrl(url, authentication) {
|
|
|
131
139
|
* @param useAsync a boolean to control if we will use an async request
|
|
132
140
|
* @return A promise that will resolve when the request has completed
|
|
133
141
|
*/
|
|
134
|
-
export function addToServiceDefinition(url, options, skipRetry, useAsync) {
|
|
135
|
-
if (skipRetry === void 0) { skipRetry = false; }
|
|
136
|
-
if (useAsync === void 0) { useAsync = false; }
|
|
142
|
+
export function addToServiceDefinition(url, options, skipRetry = false, useAsync = false) {
|
|
137
143
|
/* istanbul ignore else */
|
|
138
144
|
if (useAsync) {
|
|
139
|
-
options.params =
|
|
145
|
+
options.params = { ...options.params, async: true };
|
|
140
146
|
}
|
|
141
|
-
return new Promise(
|
|
142
|
-
svcAdminAddToServiceDefinition(url, options).then(
|
|
143
|
-
checkRequestStatus(result, options.authentication).then(
|
|
144
|
-
},
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
svcAdminAddToServiceDefinition(url, options).then((result) => {
|
|
149
|
+
checkRequestStatus(result, options.authentication).then(() => resolve(null), e => reject(fail(e)));
|
|
150
|
+
}, e => {
|
|
145
151
|
if (!skipRetry) {
|
|
146
|
-
addToServiceDefinition(url, options, true, true).then(
|
|
152
|
+
addToServiceDefinition(url, options, true, true).then(() => resolve(null), e => reject(e));
|
|
147
153
|
}
|
|
148
154
|
else {
|
|
149
155
|
reject(fail(e));
|
|
@@ -160,21 +166,21 @@ export function addToServiceDefinition(url, options, skipRetry, useAsync) {
|
|
|
160
166
|
* @return A promise that will resolve when the request has completed
|
|
161
167
|
*/
|
|
162
168
|
export function checkRequestStatus(result, authentication) {
|
|
163
|
-
return new Promise(
|
|
169
|
+
return new Promise((resolve, reject) => {
|
|
164
170
|
if (result.statusURL) {
|
|
165
|
-
|
|
166
|
-
request(result.statusURL, { authentication
|
|
171
|
+
const checkStatus = setInterval(() => {
|
|
172
|
+
request(result.statusURL, { authentication }).then(r => {
|
|
167
173
|
/* istanbul ignore else */
|
|
168
174
|
if (r.status === "Completed") {
|
|
169
|
-
clearInterval(
|
|
175
|
+
clearInterval(checkStatus);
|
|
170
176
|
resolve();
|
|
171
177
|
}
|
|
172
178
|
else if (r.status === "Failed") {
|
|
173
|
-
clearInterval(
|
|
179
|
+
clearInterval(checkStatus);
|
|
174
180
|
reject(r);
|
|
175
181
|
}
|
|
176
|
-
},
|
|
177
|
-
clearInterval(
|
|
182
|
+
}, e => {
|
|
183
|
+
clearInterval(checkStatus);
|
|
178
184
|
reject(e);
|
|
179
185
|
});
|
|
180
186
|
}, 2000);
|
|
@@ -196,7 +202,7 @@ export function _validateExtent(extent) {
|
|
|
196
202
|
// in some cases orgs can have invalid extents defined
|
|
197
203
|
// this is a simple validate function that will ensure coordiantes are numbers
|
|
198
204
|
// using -179,-89,179,89 because the project call is returning "NaN" when using -180,-90,180,90
|
|
199
|
-
|
|
205
|
+
const hasInvalid = typeof extent.xmin !== "number" ||
|
|
200
206
|
typeof extent.xmax !== "number" ||
|
|
201
207
|
typeof extent.ymax !== "number" ||
|
|
202
208
|
typeof extent.ymin !== "number";
|
|
@@ -224,29 +230,29 @@ export function _validateExtent(extent) {
|
|
|
224
230
|
* @private
|
|
225
231
|
*/
|
|
226
232
|
export function convertExtentWithFallback(extent, fallbackExtent, outSR, geometryServiceUrl, authentication) {
|
|
227
|
-
return new Promise(
|
|
228
|
-
|
|
233
|
+
return new Promise((resolve, reject) => {
|
|
234
|
+
const defaultExtent = {
|
|
229
235
|
xmin: -179,
|
|
230
236
|
xmax: 179,
|
|
231
237
|
ymin: -89,
|
|
232
238
|
ymax: 89,
|
|
233
239
|
spatialReference: { wkid: 4326 }
|
|
234
240
|
};
|
|
235
|
-
convertExtent(_validateExtent(extent), outSR, geometryServiceUrl, authentication).then(
|
|
241
|
+
convertExtent(_validateExtent(extent), outSR, geometryServiceUrl, authentication).then(extentResponse => {
|
|
236
242
|
// in some cases project will complete successfully but return "NaN" values
|
|
237
243
|
// check for this and call convert again if it does
|
|
238
|
-
|
|
239
|
-
|
|
244
|
+
const extentResponseString = JSON.stringify(extentResponse);
|
|
245
|
+
const validatedExtent = JSON.stringify(_validateExtent(extentResponse));
|
|
240
246
|
if (extentResponseString === validatedExtent) {
|
|
241
247
|
resolve(extentResponse);
|
|
242
248
|
}
|
|
243
249
|
else {
|
|
244
|
-
convertExtent(fallbackExtent || defaultExtent, outSR, geometryServiceUrl, authentication).then(resolve,
|
|
250
|
+
convertExtent(fallbackExtent || defaultExtent, outSR, geometryServiceUrl, authentication).then(resolve, e => reject(fail(e)));
|
|
245
251
|
}
|
|
246
252
|
},
|
|
247
253
|
// if convert fails try again with default global extent
|
|
248
|
-
|
|
249
|
-
convertExtent(defaultExtent, outSR, geometryServiceUrl, authentication).then(resolve,
|
|
254
|
+
() => {
|
|
255
|
+
convertExtent(defaultExtent, outSR, geometryServiceUrl, authentication).then(resolve, e => reject(fail(e)));
|
|
250
256
|
});
|
|
251
257
|
});
|
|
252
258
|
}
|
|
@@ -260,10 +266,10 @@ export function convertExtentWithFallback(extent, fallbackExtent, outSR, geometr
|
|
|
260
266
|
* @return Original extent if it's already using outSR or the extents projected into the outSR
|
|
261
267
|
*/
|
|
262
268
|
export function convertExtent(extent, outSR, geometryServiceUrl, authentication) {
|
|
263
|
-
|
|
264
|
-
return new Promise(
|
|
269
|
+
const _requestOptions = Object.assign({}, authentication);
|
|
270
|
+
return new Promise((resolve, reject) => {
|
|
265
271
|
// tslint:disable-next-line:no-unnecessary-type-assertion
|
|
266
|
-
if (extent.spatialReference.wkid ===
|
|
272
|
+
if (extent.spatialReference.wkid === outSR?.wkid || !outSR) {
|
|
267
273
|
resolve(extent);
|
|
268
274
|
}
|
|
269
275
|
else {
|
|
@@ -274,11 +280,11 @@ export function convertExtent(extent, outSR, geometryServiceUrl, authentication)
|
|
|
274
280
|
outSR: outSR.wkid,
|
|
275
281
|
extentOfInterest: JSON.stringify(extent)
|
|
276
282
|
};
|
|
277
|
-
request(checkUrlPathTermination(geometryServiceUrl) + "findTransformations", _requestOptions).then(
|
|
278
|
-
|
|
283
|
+
request(checkUrlPathTermination(geometryServiceUrl) + "findTransformations", _requestOptions).then(response => {
|
|
284
|
+
const transformations = response && response.transformations
|
|
279
285
|
? response.transformations
|
|
280
286
|
: undefined;
|
|
281
|
-
|
|
287
|
+
let transformation;
|
|
282
288
|
if (transformations && transformations.length > 0) {
|
|
283
289
|
// if a forward single transformation is found use that...otherwise check for and use composite
|
|
284
290
|
transformation = transformations[0].wkid
|
|
@@ -301,8 +307,8 @@ export function convertExtent(extent, outSR, geometryServiceUrl, authentication)
|
|
|
301
307
|
},
|
|
302
308
|
transformation: transformation
|
|
303
309
|
};
|
|
304
|
-
request(checkUrlPathTermination(geometryServiceUrl) + "project", _requestOptions).then(
|
|
305
|
-
|
|
310
|
+
request(checkUrlPathTermination(geometryServiceUrl) + "project", _requestOptions).then(projectResponse => {
|
|
311
|
+
const projectGeom = projectResponse.geometries.length === 2
|
|
306
312
|
? projectResponse.geometries
|
|
307
313
|
: undefined;
|
|
308
314
|
if (projectGeom) {
|
|
@@ -317,8 +323,8 @@ export function convertExtent(extent, outSR, geometryServiceUrl, authentication)
|
|
|
317
323
|
else {
|
|
318
324
|
resolve(undefined);
|
|
319
325
|
}
|
|
320
|
-
},
|
|
321
|
-
},
|
|
326
|
+
}, e => reject(fail(e)));
|
|
327
|
+
}, e => reject(fail(e)));
|
|
322
328
|
}
|
|
323
329
|
});
|
|
324
330
|
}
|
|
@@ -331,13 +337,13 @@ export function convertExtent(extent, outSR, geometryServiceUrl, authentication)
|
|
|
331
337
|
* @return A promise that will resolve with an object reporting success and the Solution id
|
|
332
338
|
*/
|
|
333
339
|
export function createFeatureService(newItemTemplate, authentication, templateDictionary) {
|
|
334
|
-
return new Promise(
|
|
340
|
+
return new Promise((resolve, reject) => {
|
|
335
341
|
// Create item
|
|
336
|
-
_getCreateServiceOptions(newItemTemplate, authentication, templateDictionary).then(
|
|
337
|
-
svcAdminCreateFeatureService(createOptions).then(
|
|
342
|
+
_getCreateServiceOptions(newItemTemplate, authentication, templateDictionary).then(createOptions => {
|
|
343
|
+
svcAdminCreateFeatureService(createOptions).then(createResponse => {
|
|
338
344
|
resolve(createResponse);
|
|
339
|
-
},
|
|
340
|
-
},
|
|
345
|
+
}, e => reject(fail(e)));
|
|
346
|
+
}, e => reject(fail(e)));
|
|
341
347
|
});
|
|
342
348
|
}
|
|
343
349
|
/**
|
|
@@ -355,29 +361,30 @@ export function createFeatureService(newItemTemplate, authentication, templateDi
|
|
|
355
361
|
* @param access Access to set for item: "public", "org", "private"
|
|
356
362
|
* @return A promise that will resolve with an object reporting success or failure and the Solution id
|
|
357
363
|
*/
|
|
358
|
-
export function createFullItem(itemInfo, folderId, destinationAuthentication, itemThumbnailUrl, itemThumbnailAuthentication, dataFile, metadataFile, resourcesFiles, access) {
|
|
359
|
-
|
|
360
|
-
return new Promise(function (resolve, reject) {
|
|
364
|
+
export function createFullItem(itemInfo, folderId, destinationAuthentication, itemThumbnailUrl, itemThumbnailAuthentication, dataFile, metadataFile, resourcesFiles, access = "private") {
|
|
365
|
+
return new Promise((resolve, reject) => {
|
|
361
366
|
// Create item
|
|
362
|
-
|
|
363
|
-
item:
|
|
364
|
-
|
|
367
|
+
const createOptions = {
|
|
368
|
+
item: {
|
|
369
|
+
...itemInfo
|
|
370
|
+
},
|
|
371
|
+
folderId,
|
|
365
372
|
authentication: destinationAuthentication
|
|
366
373
|
};
|
|
367
374
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
368
|
-
addTokenToUrl(itemThumbnailUrl, itemThumbnailAuthentication).then(
|
|
375
|
+
addTokenToUrl(itemThumbnailUrl, itemThumbnailAuthentication).then(updatedThumbnailUrl => {
|
|
369
376
|
/* istanbul ignore else */
|
|
370
377
|
if (updatedThumbnailUrl) {
|
|
371
378
|
createOptions.item.thumbnailurl = appendQueryParam(updatedThumbnailUrl, "w=400");
|
|
372
379
|
}
|
|
373
|
-
createItemInFolder(createOptions).then(
|
|
380
|
+
createItemInFolder(createOptions).then(createResponse => {
|
|
374
381
|
if (createResponse.success) {
|
|
375
|
-
|
|
382
|
+
let accessDef;
|
|
376
383
|
// Set access if it is not AGOL default
|
|
377
384
|
// Set the access manually since the access value in createItem appears to be ignored
|
|
378
385
|
// Need to run serially; will not work reliably if done in parallel with adding the data section
|
|
379
386
|
if (access !== "private") {
|
|
380
|
-
|
|
387
|
+
const accessOptions = {
|
|
381
388
|
id: createResponse.id,
|
|
382
389
|
access: access === "public" ? "public" : "org",
|
|
383
390
|
authentication: destinationAuthentication
|
|
@@ -390,8 +397,8 @@ export function createFullItem(itemInfo, folderId, destinationAuthentication, it
|
|
|
390
397
|
});
|
|
391
398
|
}
|
|
392
399
|
// Now add attached items
|
|
393
|
-
accessDef.then(
|
|
394
|
-
|
|
400
|
+
accessDef.then(() => {
|
|
401
|
+
const updateDefs = [];
|
|
395
402
|
// Add the data section
|
|
396
403
|
if (dataFile) {
|
|
397
404
|
updateDefs.push(_addItemDataFile(createResponse.id, dataFile, destinationAuthentication));
|
|
@@ -400,9 +407,9 @@ export function createFullItem(itemInfo, folderId, destinationAuthentication, it
|
|
|
400
407
|
// same time to the same item
|
|
401
408
|
if (Array.isArray(resourcesFiles) &&
|
|
402
409
|
resourcesFiles.length > 0) {
|
|
403
|
-
updateDefs.push(new Promise(
|
|
404
|
-
createZip("resources.zip", resourcesFiles).then(
|
|
405
|
-
|
|
410
|
+
updateDefs.push(new Promise((rsrcResolve, rsrcReject) => {
|
|
411
|
+
createZip("resources.zip", resourcesFiles).then((zipfile) => {
|
|
412
|
+
const addResourceOptions = {
|
|
406
413
|
id: createResponse.id,
|
|
407
414
|
resource: zipfile,
|
|
408
415
|
authentication: destinationAuthentication,
|
|
@@ -419,13 +426,13 @@ export function createFullItem(itemInfo, folderId, destinationAuthentication, it
|
|
|
419
426
|
updateDefs.push(_addItemMetadataFile(createResponse.id, metadataFile, destinationAuthentication));
|
|
420
427
|
}
|
|
421
428
|
// Wait until all adds are done
|
|
422
|
-
Promise.all(updateDefs).then(
|
|
423
|
-
},
|
|
429
|
+
Promise.all(updateDefs).then(() => resolve(createResponse), e => reject(fail(e)));
|
|
430
|
+
}, e => reject(fail(e)));
|
|
424
431
|
}
|
|
425
432
|
else {
|
|
426
433
|
reject(fail());
|
|
427
434
|
}
|
|
428
|
-
},
|
|
435
|
+
}, e => reject(fail(e)));
|
|
429
436
|
});
|
|
430
437
|
});
|
|
431
438
|
}
|
|
@@ -440,13 +447,16 @@ export function createFullItem(itemInfo, folderId, destinationAuthentication, it
|
|
|
440
447
|
* @param access Access to set for item: "public", "org", "private"
|
|
441
448
|
* @return A promise that will resolve with an object reporting success and the Solution id
|
|
442
449
|
*/
|
|
443
|
-
export function createItemWithData(itemInfo, dataInfo, authentication, folderId, access) {
|
|
444
|
-
|
|
445
|
-
return new Promise(function (resolve, reject) {
|
|
450
|
+
export function createItemWithData(itemInfo, dataInfo, authentication, folderId, access = "private") {
|
|
451
|
+
return new Promise((resolve, reject) => {
|
|
446
452
|
// Create item
|
|
447
|
-
|
|
448
|
-
item:
|
|
449
|
-
|
|
453
|
+
const createOptions = {
|
|
454
|
+
item: {
|
|
455
|
+
title: "_",
|
|
456
|
+
...itemInfo,
|
|
457
|
+
data: dataInfo
|
|
458
|
+
},
|
|
459
|
+
folderId,
|
|
450
460
|
authentication: authentication
|
|
451
461
|
};
|
|
452
462
|
if (itemInfo.thumbnail) {
|
|
@@ -456,23 +466,23 @@ export function createItemWithData(itemInfo, dataInfo, authentication, folderId,
|
|
|
456
466
|
};
|
|
457
467
|
delete createOptions.item.thumbnail;
|
|
458
468
|
}
|
|
459
|
-
createItemInFolder(createOptions).then(
|
|
469
|
+
createItemInFolder(createOptions).then(createResponse => {
|
|
460
470
|
if (createResponse.success) {
|
|
461
471
|
if (access !== "private") {
|
|
462
472
|
// Set access if it is not AGOL default
|
|
463
473
|
// Set the access manually since the access value in createItem appears to be ignored
|
|
464
|
-
|
|
474
|
+
const accessOptions = {
|
|
465
475
|
id: createResponse.id,
|
|
466
476
|
access: access === "public" ? "public" : "org",
|
|
467
477
|
authentication: authentication
|
|
468
478
|
};
|
|
469
|
-
setItemAccess(accessOptions).then(
|
|
479
|
+
setItemAccess(accessOptions).then(() => {
|
|
470
480
|
resolve({
|
|
471
481
|
folder: createResponse.folder,
|
|
472
482
|
id: createResponse.id,
|
|
473
483
|
success: true
|
|
474
484
|
});
|
|
475
|
-
},
|
|
485
|
+
}, e => reject(fail(e)));
|
|
476
486
|
}
|
|
477
487
|
else {
|
|
478
488
|
resolve({
|
|
@@ -485,7 +495,7 @@ export function createItemWithData(itemInfo, dataInfo, authentication, folderId,
|
|
|
485
495
|
else {
|
|
486
496
|
reject(fail());
|
|
487
497
|
}
|
|
488
|
-
},
|
|
498
|
+
}, e => reject(fail(e)));
|
|
489
499
|
});
|
|
490
500
|
}
|
|
491
501
|
/**
|
|
@@ -499,18 +509,18 @@ export function createItemWithData(itemInfo, dataInfo, authentication, folderId,
|
|
|
499
509
|
* @return Id of created folder
|
|
500
510
|
*/
|
|
501
511
|
export function createUniqueFolder(title, templateDictionary, authentication) {
|
|
502
|
-
return new Promise(
|
|
512
|
+
return new Promise((resolve, reject) => {
|
|
503
513
|
// Get a title that is not already in use
|
|
504
|
-
|
|
505
|
-
|
|
514
|
+
const folderTitle = getUniqueTitle(title, templateDictionary, "user.folders");
|
|
515
|
+
const folderCreationParam = {
|
|
506
516
|
title: folderTitle,
|
|
507
517
|
authentication: authentication
|
|
508
518
|
};
|
|
509
|
-
createFolder(folderCreationParam).then(
|
|
519
|
+
createFolder(folderCreationParam).then(ok => resolve(ok), err => {
|
|
510
520
|
// If the name already exists, we'll try again
|
|
511
|
-
|
|
521
|
+
const errorDetails = getProp(err, "response.error.details");
|
|
512
522
|
if (Array.isArray(errorDetails) && errorDetails.length > 0) {
|
|
513
|
-
|
|
523
|
+
const nameNotAvailMsg = "Folder title '" + folderTitle + "' not available.";
|
|
514
524
|
if (errorDetails.indexOf(nameNotAvailMsg) >= 0) {
|
|
515
525
|
// Create the user.folders property if it doesn't exist
|
|
516
526
|
/* istanbul ignore else */
|
|
@@ -539,38 +549,56 @@ export function createUniqueFolder(title, templateDictionary, authentication) {
|
|
|
539
549
|
* @param title Group title, used as-is if possible and with suffix otherwise
|
|
540
550
|
* @param templateDictionary Hash of facts: org URL, adlib replacements, user
|
|
541
551
|
* @param authentication Credentials for creating group
|
|
552
|
+
* @param owner Optional arg for the Tracking owner
|
|
553
|
+
* If the tracking owner is not the one deploying the solution
|
|
554
|
+
* tracker groups will be created under the deployment user but
|
|
555
|
+
* will be reassigned to the tracking owner.
|
|
542
556
|
* @return Information about created group
|
|
543
557
|
*/
|
|
544
|
-
export function createUniqueGroup(title, groupItem, templateDictionary, authentication) {
|
|
545
|
-
return new Promise(
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
558
|
+
export function createUniqueGroup(title, groupItem, templateDictionary, authentication, owner) {
|
|
559
|
+
return new Promise((resolve, reject) => {
|
|
560
|
+
let groupsPromise;
|
|
561
|
+
// when working with tracker we need to consider the groups of the deploying user as well as the groups
|
|
562
|
+
// of the tracking user...must be unique for both
|
|
563
|
+
if (owner && owner !== authentication.username) {
|
|
564
|
+
groupsPromise = searchAllGroups(`(owner:${owner}) orgid:${templateDictionary.organization.id}`, authentication);
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
groupsPromise = Promise.resolve([]);
|
|
568
|
+
}
|
|
569
|
+
// first get the tracker owner groups
|
|
570
|
+
groupsPromise.then(groups => {
|
|
571
|
+
templateDictionary["allGroups"] =
|
|
572
|
+
groups.concat(getProp(templateDictionary, "user.groups"));
|
|
573
|
+
// Get a title that is not already in use
|
|
574
|
+
groupItem.title = getUniqueTitle(title, templateDictionary, "allGroups");
|
|
575
|
+
const groupCreationParam = {
|
|
576
|
+
group: groupItem,
|
|
577
|
+
authentication: authentication
|
|
578
|
+
};
|
|
579
|
+
createGroup(groupCreationParam).then(resolve, err => {
|
|
580
|
+
// If the name already exists, we'll try again
|
|
581
|
+
const errorDetails = getProp(err, "response.error.details");
|
|
582
|
+
if (Array.isArray(errorDetails) && errorDetails.length > 0) {
|
|
583
|
+
const nameNotAvailMsg = "You already have a group named '" +
|
|
584
|
+
groupItem.title +
|
|
585
|
+
"'. Try a different name.";
|
|
586
|
+
if (errorDetails.indexOf(nameNotAvailMsg) >= 0) {
|
|
587
|
+
templateDictionary.user.groups.push({
|
|
588
|
+
title: groupItem.title
|
|
589
|
+
});
|
|
590
|
+
createUniqueGroup(title, groupItem, templateDictionary, authentication).then(resolve, reject);
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
reject(err);
|
|
594
|
+
}
|
|
564
595
|
}
|
|
565
596
|
else {
|
|
597
|
+
// Otherwise, error out
|
|
566
598
|
reject(err);
|
|
567
599
|
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// Otherwise, error out
|
|
571
|
-
reject(err);
|
|
572
|
-
}
|
|
573
|
-
});
|
|
600
|
+
});
|
|
601
|
+
}, e => reject(e));
|
|
574
602
|
});
|
|
575
603
|
}
|
|
576
604
|
/**
|
|
@@ -582,16 +610,17 @@ export function createUniqueGroup(title, groupItem, templateDictionary, authenti
|
|
|
582
610
|
* @return A promise that will resolve a list of dependencies
|
|
583
611
|
*/
|
|
584
612
|
export function extractDependencies(itemTemplate, authentication) {
|
|
585
|
-
|
|
586
|
-
return new Promise(
|
|
613
|
+
const dependencies = [];
|
|
614
|
+
return new Promise((resolve, reject) => {
|
|
587
615
|
// Get service dependencies when the item is a view
|
|
588
|
-
|
|
616
|
+
// This step is skipped for tracker views as they will already have a source service in the org
|
|
617
|
+
if (itemTemplate.properties.service.isView && itemTemplate.item.url && !isTrackingViewTemplate(itemTemplate)) {
|
|
589
618
|
request(checkUrlPathTermination(itemTemplate.item.url) + "sources?f=json", {
|
|
590
619
|
authentication: authentication
|
|
591
|
-
}).then(
|
|
620
|
+
}).then(response => {
|
|
592
621
|
/* istanbul ignore else */
|
|
593
622
|
if (response && response.services) {
|
|
594
|
-
response.services.forEach(
|
|
623
|
+
response.services.forEach((layer) => {
|
|
595
624
|
dependencies.push({
|
|
596
625
|
id: layer.serviceItemId,
|
|
597
626
|
name: layer.name
|
|
@@ -599,7 +628,7 @@ export function extractDependencies(itemTemplate, authentication) {
|
|
|
599
628
|
});
|
|
600
629
|
}
|
|
601
630
|
resolve(dependencies);
|
|
602
|
-
},
|
|
631
|
+
}, e => reject(fail(e)));
|
|
603
632
|
}
|
|
604
633
|
else if (isWorkforceProject(itemTemplate)) {
|
|
605
634
|
resolve(getWorkforceDependencies(itemTemplate, dependencies));
|
|
@@ -618,37 +647,39 @@ export function extractDependencies(itemTemplate, authentication) {
|
|
|
618
647
|
* @return A promise that will resolve a list of dependencies
|
|
619
648
|
*/
|
|
620
649
|
export function getLayers(serviceUrl, layerList, authentication) {
|
|
621
|
-
return new Promise(
|
|
650
|
+
return new Promise((resolve, reject) => {
|
|
622
651
|
if (layerList.length === 0) {
|
|
623
652
|
resolve([]);
|
|
624
653
|
}
|
|
625
654
|
// get the admin URL
|
|
626
655
|
serviceUrl = serviceUrl.replace("/rest/services", "/rest/admin/services");
|
|
627
|
-
|
|
628
|
-
layerList.forEach(
|
|
629
|
-
|
|
656
|
+
const requestsDfd = [];
|
|
657
|
+
layerList.forEach(layer => {
|
|
658
|
+
const requestOptions = {
|
|
630
659
|
authentication: authentication
|
|
631
660
|
};
|
|
632
661
|
requestsDfd.push(request(checkUrlPathTermination(serviceUrl) + layer["id"] + "?f=json", requestOptions));
|
|
633
662
|
});
|
|
634
663
|
// Wait until all layers are heard from
|
|
635
|
-
Promise.all(requestsDfd).then(
|
|
664
|
+
Promise.all(requestsDfd).then(layers => resolve(layers), e => reject(fail(e)));
|
|
636
665
|
});
|
|
637
666
|
}
|
|
638
667
|
/**
|
|
639
668
|
* Add additional options to a layers definition.
|
|
640
669
|
*
|
|
641
670
|
* @param args The IPostProcessArgs for the request(s)
|
|
671
|
+
* @param isPortal boolean to indicate if we are deploying to portal
|
|
672
|
+
*
|
|
642
673
|
* @return An array of update instructions
|
|
643
674
|
* @private
|
|
644
675
|
*/
|
|
645
676
|
export function getLayerUpdates(args, isPortal) {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
677
|
+
const adminUrl = args.itemTemplate.item.url.replace("rest/services", "rest/admin/services");
|
|
678
|
+
const updates = [];
|
|
679
|
+
const refresh = _getUpdate(adminUrl, null, null, args, "refresh");
|
|
649
680
|
updates.push(refresh);
|
|
650
|
-
Object.keys(args.objects).forEach(
|
|
651
|
-
|
|
681
|
+
Object.keys(args.objects).forEach(id => {
|
|
682
|
+
const obj = Object.assign({}, args.objects[id]);
|
|
652
683
|
// These properties cannot be set in the update definition when working with portal
|
|
653
684
|
if (isPortal) {
|
|
654
685
|
deleteProps(obj, ["type", "id", "relationships", "sourceServiceFields"]);
|
|
@@ -667,13 +698,20 @@ export function getLayerUpdates(args, isPortal) {
|
|
|
667
698
|
updates.push(refresh);
|
|
668
699
|
}
|
|
669
700
|
});
|
|
701
|
+
// issue: #706
|
|
702
|
+
// Add source service relationships
|
|
703
|
+
// views will now always add all layers in a single call and will inherit the relationships from the source service
|
|
670
704
|
if (!args.itemTemplate.properties.service.isView) {
|
|
671
|
-
|
|
705
|
+
const relUpdates = _getRelationshipUpdates({
|
|
672
706
|
message: "updated layer relationships",
|
|
673
707
|
objects: args.objects,
|
|
674
708
|
itemTemplate: args.itemTemplate,
|
|
675
709
|
authentication: args.authentication
|
|
676
710
|
});
|
|
711
|
+
// issue: #724
|
|
712
|
+
// In portal the order the relationships are added needs to follow the layer order
|
|
713
|
+
// otherwise the relationship IDs will be reset
|
|
714
|
+
relUpdates.layers = _sortRelationships(args.itemTemplate.properties.layers, args.itemTemplate.properties.tables, relUpdates);
|
|
677
715
|
/* istanbul ignore else */
|
|
678
716
|
if (relUpdates.layers.length > 0) {
|
|
679
717
|
updates.push(_getUpdate(adminUrl, null, relUpdates, args, "add"));
|
|
@@ -682,6 +720,33 @@ export function getLayerUpdates(args, isPortal) {
|
|
|
682
720
|
}
|
|
683
721
|
return updates;
|
|
684
722
|
}
|
|
723
|
+
/**
|
|
724
|
+
* Sorts relationships based on order of supporting layers and tables in the service definition
|
|
725
|
+
*
|
|
726
|
+
* @param layers the layers from the service
|
|
727
|
+
* @param tables the tables from the service
|
|
728
|
+
* @param relUpdates the relationships to add for the service
|
|
729
|
+
*
|
|
730
|
+
* @return An array with relationships that have been sorted
|
|
731
|
+
*/
|
|
732
|
+
export function _sortRelationships(layers, tables, relUpdates) {
|
|
733
|
+
const ids = [].concat(layers.map((l) => l.id), tables.map((t) => t.id));
|
|
734
|
+
// In portal the order the relationships are added needs to follow the layer order
|
|
735
|
+
// otherwise the relationship IDs will be reset
|
|
736
|
+
const _relUpdateLayers = [];
|
|
737
|
+
ids.forEach(id => {
|
|
738
|
+
relUpdates.layers.some((relUpdate) => {
|
|
739
|
+
if (id === relUpdate.id) {
|
|
740
|
+
_relUpdateLayers.push(relUpdate);
|
|
741
|
+
return true;
|
|
742
|
+
}
|
|
743
|
+
else {
|
|
744
|
+
return false;
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
});
|
|
748
|
+
return _relUpdateLayers;
|
|
749
|
+
}
|
|
685
750
|
/**
|
|
686
751
|
* Update view service when sourceSchemaChangesAllowed is true.
|
|
687
752
|
*
|
|
@@ -694,16 +759,16 @@ export function getLayerUpdates(args, isPortal) {
|
|
|
694
759
|
* @return An array of update instructions
|
|
695
760
|
*/
|
|
696
761
|
export function getFinalServiceUpdates(itemTemplate, authentication, updates) {
|
|
697
|
-
|
|
698
|
-
|
|
762
|
+
const sourceSchemaChangesAllowed = getProp(itemTemplate, "properties.service.sourceSchemaChangesAllowed");
|
|
763
|
+
const isView = getProp(itemTemplate, "properties.service.isView");
|
|
699
764
|
/* istanbul ignore else */
|
|
700
765
|
if (sourceSchemaChangesAllowed && isView) {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
authentication
|
|
766
|
+
const adminUrl = itemTemplate.item.url.replace("rest/services", "rest/admin/services");
|
|
767
|
+
const args = {
|
|
768
|
+
authentication,
|
|
704
769
|
message: "final service update"
|
|
705
770
|
};
|
|
706
|
-
|
|
771
|
+
const serviceUpdates = { sourceSchemaChangesAllowed };
|
|
707
772
|
updates.push(_getUpdate(adminUrl, null, serviceUpdates, args, "update"));
|
|
708
773
|
}
|
|
709
774
|
return updates;
|
|
@@ -720,11 +785,9 @@ export function getFinalServiceUpdates(itemTemplate, authentication, updates) {
|
|
|
720
785
|
* @private
|
|
721
786
|
*/
|
|
722
787
|
/* istanbul ignore else */
|
|
723
|
-
export function getRequest(update, skipRetry, useAsync) {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
return new Promise(function (resolve, reject) {
|
|
727
|
-
var options = {
|
|
788
|
+
export function getRequest(update, skipRetry = false, useAsync = false) {
|
|
789
|
+
return new Promise((resolve, reject) => {
|
|
790
|
+
const options = {
|
|
728
791
|
params: update.params,
|
|
729
792
|
authentication: update.args.authentication
|
|
730
793
|
};
|
|
@@ -732,13 +795,13 @@ export function getRequest(update, skipRetry, useAsync) {
|
|
|
732
795
|
if ((useAsync && update.url.indexOf("addToDefinition") > -1) ||
|
|
733
796
|
update.url.indexOf("updateDefinition") > -1 ||
|
|
734
797
|
update.url.indexOf("deleteFromDefinition") > -1) {
|
|
735
|
-
options.params =
|
|
798
|
+
options.params = { ...options.params, async: true };
|
|
736
799
|
}
|
|
737
|
-
request(update.url, options).then(
|
|
738
|
-
checkRequestStatus(result, options.authentication).then(
|
|
739
|
-
},
|
|
800
|
+
request(update.url, options).then(result => {
|
|
801
|
+
checkRequestStatus(result, options.authentication).then(() => resolve(null), e => reject(fail(e)));
|
|
802
|
+
}, (e) => {
|
|
740
803
|
if (!skipRetry) {
|
|
741
|
-
getRequest(update, true, true).then(
|
|
804
|
+
getRequest(update, true, true).then(() => resolve(), e => reject(e));
|
|
742
805
|
}
|
|
743
806
|
else {
|
|
744
807
|
reject(e);
|
|
@@ -755,18 +818,18 @@ export function getRequest(update, skipRetry, useAsync) {
|
|
|
755
818
|
* @private
|
|
756
819
|
*/
|
|
757
820
|
export function getServiceLayersAndTables(itemTemplate, authentication) {
|
|
758
|
-
return new Promise(
|
|
821
|
+
return new Promise((resolve, reject) => {
|
|
759
822
|
// To have enough information for reconstructing the service, we'll supplement
|
|
760
823
|
// the item and data sections with sections for the service, full layers, and
|
|
761
824
|
// full tables
|
|
762
825
|
// Extra steps must be taken for workforce version 2
|
|
763
|
-
|
|
826
|
+
const isWorkforceService = isWorkforceProject(itemTemplate);
|
|
764
827
|
// Get the service description
|
|
765
828
|
if (itemTemplate.item.url) {
|
|
766
|
-
getFeatureServiceProperties(itemTemplate.item.url, authentication, isWorkforceService).then(
|
|
829
|
+
getFeatureServiceProperties(itemTemplate.item.url, authentication, isWorkforceService).then(properties => {
|
|
767
830
|
itemTemplate.properties = properties;
|
|
768
831
|
resolve(itemTemplate);
|
|
769
|
-
},
|
|
832
|
+
}, e => reject(fail(e)));
|
|
770
833
|
}
|
|
771
834
|
else {
|
|
772
835
|
resolve(itemTemplate);
|
|
@@ -782,10 +845,9 @@ export function getServiceLayersAndTables(itemTemplate, authentication) {
|
|
|
782
845
|
* @return A promise that will resolve with the service properties
|
|
783
846
|
* @private
|
|
784
847
|
*/
|
|
785
|
-
export function getFeatureServiceProperties(serviceUrl, authentication, workforceService) {
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
var properties = {
|
|
848
|
+
export function getFeatureServiceProperties(serviceUrl, authentication, workforceService = false) {
|
|
849
|
+
return new Promise((resolve, reject) => {
|
|
850
|
+
const properties = {
|
|
789
851
|
service: {},
|
|
790
852
|
layers: [],
|
|
791
853
|
tables: []
|
|
@@ -795,13 +857,12 @@ export function getFeatureServiceProperties(serviceUrl, authentication, workforc
|
|
|
795
857
|
// Get the service description
|
|
796
858
|
request(serviceUrl + "?f=json", {
|
|
797
859
|
authentication: authentication
|
|
798
|
-
}).then(
|
|
799
|
-
var _a;
|
|
860
|
+
}).then(serviceData => {
|
|
800
861
|
properties.service = _parseAdminServiceData(serviceData);
|
|
801
862
|
// Copy cacheMaxAge to top level so that AGO sees it when deploying the service
|
|
802
863
|
// serviceData may have set it if there isn't an adminServiceInfo
|
|
803
864
|
/* istanbul ignore else */
|
|
804
|
-
if (
|
|
865
|
+
if (serviceData.adminServiceInfo?.cacheMaxAge) {
|
|
805
866
|
properties.service.cacheMaxAge =
|
|
806
867
|
serviceData.adminServiceInfo.cacheMaxAge;
|
|
807
868
|
}
|
|
@@ -811,7 +872,7 @@ export function getFeatureServiceProperties(serviceUrl, authentication, workforc
|
|
|
811
872
|
properties.layers = serviceData.layers;
|
|
812
873
|
// Fill in properties that the service layer doesn't provide
|
|
813
874
|
// and remove properties that should not exist in the template
|
|
814
|
-
properties.layers.forEach(
|
|
875
|
+
properties.layers.forEach(layer => {
|
|
815
876
|
layer.serviceItemId = properties.service.serviceItemId;
|
|
816
877
|
layer.extent = null;
|
|
817
878
|
removeLayerOptimization(layer);
|
|
@@ -822,7 +883,7 @@ export function getFeatureServiceProperties(serviceUrl, authentication, workforc
|
|
|
822
883
|
if (serviceData.tables) {
|
|
823
884
|
properties.tables = serviceData.tables;
|
|
824
885
|
// Fill in properties that the service layer doesn't provide
|
|
825
|
-
properties.tables.forEach(
|
|
886
|
+
properties.tables.forEach(table => {
|
|
826
887
|
table.serviceItemId = properties.service.serviceItemId;
|
|
827
888
|
table.extent = null;
|
|
828
889
|
});
|
|
@@ -836,7 +897,7 @@ export function getFeatureServiceProperties(serviceUrl, authentication, workforc
|
|
|
836
897
|
else {
|
|
837
898
|
resolve(properties);
|
|
838
899
|
}
|
|
839
|
-
},
|
|
900
|
+
}, (e) => reject(fail(e)));
|
|
840
901
|
});
|
|
841
902
|
}
|
|
842
903
|
/**
|
|
@@ -847,12 +908,12 @@ export function getFeatureServiceProperties(serviceUrl, authentication, workforc
|
|
|
847
908
|
* @return A mutated version of the provided adminData
|
|
848
909
|
*/
|
|
849
910
|
export function _parseAdminServiceData(adminData) {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
setCreateProp(adminData, "layers", layers.filter(
|
|
911
|
+
const layers = adminData.layers || [];
|
|
912
|
+
const tables = adminData.tables || [];
|
|
913
|
+
setCreateProp(adminData, "layers", layers.filter(l => l.type === "Feature Layer"));
|
|
853
914
|
// TODO understand if the concat is necessary.
|
|
854
915
|
// Not sure if the admin api will ever actually return a tables collection here.
|
|
855
|
-
setCreateProp(adminData, "tables", tables.concat(layers.filter(
|
|
916
|
+
setCreateProp(adminData, "tables", tables.concat(layers.filter(l => l.type === "Table")));
|
|
856
917
|
return adminData;
|
|
857
918
|
}
|
|
858
919
|
/**
|
|
@@ -863,7 +924,7 @@ export function _parseAdminServiceData(adminData) {
|
|
|
863
924
|
* @return A boolean indicating if the invalid designation is found in the item info
|
|
864
925
|
*/
|
|
865
926
|
export function hasInvalidGroupDesignations(groupDesignations) {
|
|
866
|
-
|
|
927
|
+
const invalidGroupDesignations = ["livingatlas"];
|
|
867
928
|
return groupDesignations
|
|
868
929
|
? invalidGroupDesignations.indexOf(groupDesignations) > -1
|
|
869
930
|
: false;
|
|
@@ -876,12 +937,12 @@ export function hasInvalidGroupDesignations(groupDesignations) {
|
|
|
876
937
|
* @return A promise that will resolve with the result of the request
|
|
877
938
|
*/
|
|
878
939
|
export function removeFolder(folderId, authentication) {
|
|
879
|
-
return new Promise(
|
|
880
|
-
|
|
940
|
+
return new Promise((resolve, reject) => {
|
|
941
|
+
const requestOptions = {
|
|
881
942
|
folderId: folderId,
|
|
882
943
|
authentication: authentication
|
|
883
944
|
};
|
|
884
|
-
portalRemoveFolder(requestOptions).then(
|
|
945
|
+
portalRemoveFolder(requestOptions).then(result => (result.success ? resolve(result) : reject(result)), reject);
|
|
885
946
|
});
|
|
886
947
|
}
|
|
887
948
|
/**
|
|
@@ -892,12 +953,12 @@ export function removeFolder(folderId, authentication) {
|
|
|
892
953
|
* @return A promise that will resolve with the result of the request
|
|
893
954
|
*/
|
|
894
955
|
export function removeGroup(groupId, authentication) {
|
|
895
|
-
return new Promise(
|
|
896
|
-
|
|
956
|
+
return new Promise((resolve, reject) => {
|
|
957
|
+
const requestOptions = {
|
|
897
958
|
id: groupId,
|
|
898
959
|
authentication: authentication
|
|
899
960
|
};
|
|
900
|
-
portalRemoveGroup(requestOptions).then(
|
|
961
|
+
portalRemoveGroup(requestOptions).then(result => (result.success ? resolve(result) : reject(result)), reject);
|
|
901
962
|
});
|
|
902
963
|
}
|
|
903
964
|
/**
|
|
@@ -908,12 +969,12 @@ export function removeGroup(groupId, authentication) {
|
|
|
908
969
|
* @return A promise that will resolve with the result of the request
|
|
909
970
|
*/
|
|
910
971
|
export function removeItem(itemId, authentication) {
|
|
911
|
-
return new Promise(
|
|
912
|
-
|
|
972
|
+
return new Promise((resolve, reject) => {
|
|
973
|
+
const requestOptions = {
|
|
913
974
|
id: itemId,
|
|
914
975
|
authentication: authentication
|
|
915
976
|
};
|
|
916
|
-
portalRemoveItem(requestOptions).then(
|
|
977
|
+
portalRemoveItem(requestOptions).then(result => (result.success ? resolve(result) : reject(result)), reject);
|
|
917
978
|
});
|
|
918
979
|
}
|
|
919
980
|
/**
|
|
@@ -924,9 +985,9 @@ export function removeItem(itemId, authentication) {
|
|
|
924
985
|
* @return A promise that will resolve with the result of the request
|
|
925
986
|
*/
|
|
926
987
|
export function removeItemOrGroup(itemId, authentication) {
|
|
927
|
-
return new Promise(
|
|
928
|
-
removeItem(itemId, authentication).then(resolve,
|
|
929
|
-
removeGroup(itemId, authentication).then(resolve,
|
|
988
|
+
return new Promise((resolve, reject) => {
|
|
989
|
+
removeItem(itemId, authentication).then(resolve, error => {
|
|
990
|
+
removeGroup(itemId, authentication).then(resolve, () => reject(error));
|
|
930
991
|
});
|
|
931
992
|
});
|
|
932
993
|
}
|
|
@@ -942,13 +1003,49 @@ export function removeItemOrGroup(itemId, authentication) {
|
|
|
942
1003
|
* @see https://developers.arcgis.com/rest/users-groups-and-items/search-reference.htm
|
|
943
1004
|
*/
|
|
944
1005
|
export function searchGroups(searchString, authentication, additionalSearchOptions) {
|
|
945
|
-
|
|
1006
|
+
const searchOptions = {
|
|
946
1007
|
q: searchString,
|
|
947
|
-
params:
|
|
1008
|
+
params: {
|
|
1009
|
+
...additionalSearchOptions
|
|
1010
|
+
},
|
|
948
1011
|
authentication: authentication
|
|
949
1012
|
};
|
|
950
1013
|
return portalSearchGroups(searchOptions);
|
|
951
1014
|
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Searches for groups matching criteria recurusively.
|
|
1017
|
+
*
|
|
1018
|
+
* @param searchString Text for which to search, e.g., 'redlands+map', 'type:"Web Map" -type:"Web Mapping Application"'
|
|
1019
|
+
* @param authentication Credentials for the request to AGO
|
|
1020
|
+
* @param groups List of groups that have been found from previous requests
|
|
1021
|
+
* @param inPagingParams The paging params for the recurisve searching
|
|
1022
|
+
*
|
|
1023
|
+
* @return A promise that will resolve with all groups that meet the search criteria
|
|
1024
|
+
*/
|
|
1025
|
+
export function searchAllGroups(searchString, authentication, groups, inPagingParams) {
|
|
1026
|
+
const pagingParams = inPagingParams ? inPagingParams : {
|
|
1027
|
+
start: 0,
|
|
1028
|
+
num: 24
|
|
1029
|
+
};
|
|
1030
|
+
const additionalSearchOptions = {
|
|
1031
|
+
sortField: "title",
|
|
1032
|
+
sortOrder: "asc",
|
|
1033
|
+
...pagingParams
|
|
1034
|
+
};
|
|
1035
|
+
let finalResults = groups ? groups : [];
|
|
1036
|
+
return new Promise((resolve, reject) => {
|
|
1037
|
+
searchGroups(searchString, authentication, additionalSearchOptions).then(response => {
|
|
1038
|
+
finalResults = finalResults.concat(response.results);
|
|
1039
|
+
if (response.nextStart > 0) {
|
|
1040
|
+
pagingParams.start = response.nextStart;
|
|
1041
|
+
resolve(searchAllGroups(searchString, authentication, finalResults, pagingParams));
|
|
1042
|
+
}
|
|
1043
|
+
else {
|
|
1044
|
+
resolve(finalResults);
|
|
1045
|
+
}
|
|
1046
|
+
}, e => reject(e));
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
952
1049
|
/**
|
|
953
1050
|
* Searches for group contents matching criteria.
|
|
954
1051
|
*
|
|
@@ -964,8 +1061,8 @@ export function searchGroups(searchString, authentication, additionalSearchOptio
|
|
|
964
1061
|
* @see https://developers.arcgis.com/rest/users-groups-and-items/search-reference.htm
|
|
965
1062
|
*/
|
|
966
1063
|
export function searchGroupContents(groupId, searchString, authentication, additionalSearchOptions, portalUrl) {
|
|
967
|
-
|
|
968
|
-
groupId
|
|
1064
|
+
const searchOptions = {
|
|
1065
|
+
groupId,
|
|
969
1066
|
q: searchString,
|
|
970
1067
|
params: Object.assign({
|
|
971
1068
|
num: 100
|
|
@@ -976,27 +1073,69 @@ export function searchGroupContents(groupId, searchString, authentication, addit
|
|
|
976
1073
|
// If search options include `categories`, switch to new arcgis-rest-js format
|
|
977
1074
|
/* istanbul ignore else */
|
|
978
1075
|
if (Array.isArray(searchOptions.params.categories)) {
|
|
979
|
-
searchOptions.params.categories = searchOptions.params.categories.map(
|
|
1076
|
+
searchOptions.params.categories = searchOptions.params.categories.map(andGroup => andGroup.split(","));
|
|
980
1077
|
}
|
|
981
1078
|
return searchGroupContent(searchOptions);
|
|
982
1079
|
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Reassign ownership of a group
|
|
1082
|
+
*
|
|
1083
|
+
* @param groupId Group to remove users from
|
|
1084
|
+
* @param userName The new owner for the group
|
|
1085
|
+
* @param authentication Credentials for the request to
|
|
1086
|
+
*
|
|
1087
|
+
* @return A promise that will resolve after the group ownership has been assigned
|
|
1088
|
+
*
|
|
1089
|
+
*/
|
|
1090
|
+
export function reassignGroup(groupId, userName, authentication) {
|
|
1091
|
+
const requestOptions = {
|
|
1092
|
+
authentication: authentication,
|
|
1093
|
+
params: {
|
|
1094
|
+
targetUsername: userName
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
return request(`${authentication.portal}/community/groups/${groupId}/reassign`, requestOptions);
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Remove users from a group
|
|
1101
|
+
*
|
|
1102
|
+
* @param groupId Group to remove users from
|
|
1103
|
+
* @param users List of users to remove from the group
|
|
1104
|
+
* @param authentication Credentials for the request to
|
|
1105
|
+
*
|
|
1106
|
+
* @return A promise that will resolve after the users have been removed
|
|
1107
|
+
*
|
|
1108
|
+
*/
|
|
1109
|
+
export function removeUsers(groupId, users, authentication) {
|
|
1110
|
+
return portalRemoveGroupUsers({
|
|
1111
|
+
id: groupId,
|
|
1112
|
+
users,
|
|
1113
|
+
authentication
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
983
1116
|
/**
|
|
984
1117
|
* Shares an item to the defined group
|
|
985
1118
|
*
|
|
986
1119
|
* @param groupId Group to share with
|
|
987
1120
|
* @param id the item id to share with the group
|
|
988
1121
|
* @param destinationAuthentication Credentials for the request to AGO
|
|
1122
|
+
* @param owner owner of the group when sharing tracking items (can be different from the deploying user)
|
|
1123
|
+
*
|
|
989
1124
|
* @return A promise that will resolve after the item has been shared
|
|
990
1125
|
*
|
|
991
1126
|
*/
|
|
992
|
-
export function shareItem(groupId, id, destinationAuthentication) {
|
|
993
|
-
return new Promise(
|
|
994
|
-
|
|
995
|
-
groupId
|
|
996
|
-
id
|
|
1127
|
+
export function shareItem(groupId, id, destinationAuthentication, owner) {
|
|
1128
|
+
return new Promise((resolve, reject) => {
|
|
1129
|
+
const shareOptions = {
|
|
1130
|
+
groupId,
|
|
1131
|
+
id,
|
|
997
1132
|
authentication: destinationAuthentication
|
|
998
1133
|
};
|
|
999
|
-
|
|
1134
|
+
/* istanbul ignore else */
|
|
1135
|
+
if (owner) {
|
|
1136
|
+
shareOptions.owner = owner;
|
|
1137
|
+
}
|
|
1138
|
+
shareItemWithGroup(shareOptions).then(() => resolve(null), (e) => reject(fail(e)));
|
|
1000
1139
|
});
|
|
1001
1140
|
}
|
|
1002
1141
|
/**
|
|
@@ -1010,14 +1149,16 @@ export function shareItem(groupId, id, destinationAuthentication) {
|
|
|
1010
1149
|
* @return
|
|
1011
1150
|
*/
|
|
1012
1151
|
export function updateItem(itemInfo, authentication, folderId, additionalParams) {
|
|
1013
|
-
return new Promise(
|
|
1014
|
-
|
|
1152
|
+
return new Promise((resolve, reject) => {
|
|
1153
|
+
const updateOptions = {
|
|
1015
1154
|
item: itemInfo,
|
|
1016
1155
|
folderId: folderId,
|
|
1017
1156
|
authentication: authentication,
|
|
1018
|
-
params:
|
|
1157
|
+
params: {
|
|
1158
|
+
...(additionalParams ?? {})
|
|
1159
|
+
}
|
|
1019
1160
|
};
|
|
1020
|
-
portalUpdateItem(updateOptions).then(
|
|
1161
|
+
portalUpdateItem(updateOptions).then(response => (response.success ? resolve(response) : reject(response)), err => reject(err));
|
|
1021
1162
|
});
|
|
1022
1163
|
}
|
|
1023
1164
|
/**
|
|
@@ -1030,9 +1171,9 @@ export function updateItem(itemInfo, authentication, folderId, additionalParams)
|
|
|
1030
1171
|
* @param access "public" or "org"
|
|
1031
1172
|
* @return
|
|
1032
1173
|
*/
|
|
1033
|
-
export function updateItemExtended(itemInfo, data, authentication, thumbnail, access) {
|
|
1034
|
-
return new Promise(
|
|
1035
|
-
|
|
1174
|
+
export function updateItemExtended(itemInfo, data, authentication, thumbnail, access, templateDictionary) {
|
|
1175
|
+
return new Promise((resolve, reject) => {
|
|
1176
|
+
const updateOptions = {
|
|
1036
1177
|
item: itemInfo,
|
|
1037
1178
|
params: {
|
|
1038
1179
|
text: data || {} // AGO ignores update if `data` is empty
|
|
@@ -1042,21 +1183,24 @@ export function updateItemExtended(itemInfo, data, authentication, thumbnail, ac
|
|
|
1042
1183
|
if (thumbnail) {
|
|
1043
1184
|
updateOptions.params.thumbnail = thumbnail;
|
|
1044
1185
|
}
|
|
1045
|
-
|
|
1186
|
+
if (isTrackingViewTemplate(undefined, itemInfo) && templateDictionary) {
|
|
1187
|
+
updateOptions.owner = templateDictionary.locationTracking.owner;
|
|
1188
|
+
}
|
|
1189
|
+
portalUpdateItem(updateOptions).then(result => {
|
|
1046
1190
|
if (access && access !== "private") {
|
|
1047
1191
|
// Set access if it is not AGOL default
|
|
1048
1192
|
// Set the access manually since the access value in createItem appears to be ignored
|
|
1049
|
-
|
|
1193
|
+
const accessOptions = {
|
|
1050
1194
|
id: itemInfo.id,
|
|
1051
1195
|
access: access === "public" ? "public" : "org",
|
|
1052
1196
|
authentication: authentication
|
|
1053
1197
|
};
|
|
1054
|
-
setItemAccess(accessOptions).then(
|
|
1198
|
+
setItemAccess(accessOptions).then(() => resolve(result), e => reject(fail(e)));
|
|
1055
1199
|
}
|
|
1056
1200
|
else {
|
|
1057
1201
|
resolve(result);
|
|
1058
1202
|
}
|
|
1059
|
-
},
|
|
1203
|
+
}, e => reject(fail(e)));
|
|
1060
1204
|
});
|
|
1061
1205
|
}
|
|
1062
1206
|
/**
|
|
@@ -1068,18 +1212,17 @@ export function updateItemExtended(itemInfo, data, authentication, thumbnail, ac
|
|
|
1068
1212
|
* @returns Promise resolving to successfulness of update
|
|
1069
1213
|
*/
|
|
1070
1214
|
export function updateItemTemplateFromDictionary(itemId, templateDictionary, authentication) {
|
|
1071
|
-
return new Promise(
|
|
1215
|
+
return new Promise((resolve, reject) => {
|
|
1072
1216
|
// Fetch the items as stored in AGO
|
|
1073
1217
|
Promise.all([
|
|
1074
1218
|
getItemBase(itemId, authentication),
|
|
1075
1219
|
getItemDataAsJson(itemId, authentication)
|
|
1076
1220
|
])
|
|
1077
|
-
.then(
|
|
1078
|
-
var _b = __read(_a, 2), item = _b[0], data = _b[1];
|
|
1221
|
+
.then(([item, data]) => {
|
|
1079
1222
|
// Do they have any variables?
|
|
1080
1223
|
if (hasUnresolvedVariables(item) || hasUnresolvedVariables(data)) {
|
|
1081
1224
|
// Update if so
|
|
1082
|
-
|
|
1225
|
+
const { item: updatedItem, data: updatedData } = replaceInTemplate({ item, data }, templateDictionary);
|
|
1083
1226
|
_reportVariablesInItem(itemId, item.type, updatedItem, updatedData);
|
|
1084
1227
|
return updateItemExtended(updatedItem, updatedData, authentication);
|
|
1085
1228
|
}
|
|
@@ -1091,8 +1234,8 @@ export function updateItemTemplateFromDictionary(itemId, templateDictionary, aut
|
|
|
1091
1234
|
});
|
|
1092
1235
|
}
|
|
1093
1236
|
})
|
|
1094
|
-
.then(
|
|
1095
|
-
.catch(
|
|
1237
|
+
.then(result => resolve(result))
|
|
1238
|
+
.catch(error => reject(error));
|
|
1096
1239
|
});
|
|
1097
1240
|
}
|
|
1098
1241
|
/**
|
|
@@ -1105,7 +1248,7 @@ export function updateItemTemplateFromDictionary(itemId, templateDictionary, aut
|
|
|
1105
1248
|
* response
|
|
1106
1249
|
*/
|
|
1107
1250
|
export function updateItemURL(id, url, authentication) {
|
|
1108
|
-
|
|
1251
|
+
const numAttempts = 3;
|
|
1109
1252
|
return _updateItemURL(id, url, authentication, numAttempts);
|
|
1110
1253
|
}
|
|
1111
1254
|
// ------------------------------------------------------------------------------------------------------------------ //
|
|
@@ -1119,9 +1262,9 @@ export function updateItemURL(id, url, authentication) {
|
|
|
1119
1262
|
* @private
|
|
1120
1263
|
*/
|
|
1121
1264
|
export function _addItemDataFile(itemId, dataFile, authentication) {
|
|
1122
|
-
return new Promise(
|
|
1123
|
-
|
|
1124
|
-
|
|
1265
|
+
return new Promise((resolve, reject) => {
|
|
1266
|
+
const addItemData = (data) => {
|
|
1267
|
+
const addDataOptions = {
|
|
1125
1268
|
id: itemId,
|
|
1126
1269
|
data: data,
|
|
1127
1270
|
authentication: authentication
|
|
@@ -1150,8 +1293,8 @@ export function _addItemDataFile(itemId, dataFile, authentication) {
|
|
|
1150
1293
|
* @private
|
|
1151
1294
|
*/
|
|
1152
1295
|
export function _addItemMetadataFile(itemId, metadataFile, authentication) {
|
|
1153
|
-
return new Promise(
|
|
1154
|
-
|
|
1296
|
+
return new Promise((resolve, reject) => {
|
|
1297
|
+
const addMetadataOptions = {
|
|
1155
1298
|
item: {
|
|
1156
1299
|
id: itemId
|
|
1157
1300
|
},
|
|
@@ -1172,10 +1315,8 @@ export function _addItemMetadataFile(itemId, metadataFile, authentication) {
|
|
|
1172
1315
|
* @private
|
|
1173
1316
|
*/
|
|
1174
1317
|
export function _countRelationships(layers) {
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
(currentLayer.relationships ? currentLayer.relationships.length : 0);
|
|
1178
|
-
};
|
|
1318
|
+
const reducer = (accumulator, currentLayer) => accumulator +
|
|
1319
|
+
(currentLayer.relationships ? currentLayer.relationships.length : 0);
|
|
1179
1320
|
return layers.reduce(reducer, 0);
|
|
1180
1321
|
}
|
|
1181
1322
|
/**
|
|
@@ -1188,28 +1329,33 @@ export function _countRelationships(layers) {
|
|
|
1188
1329
|
* @private
|
|
1189
1330
|
*/
|
|
1190
1331
|
export function _getCreateServiceOptions(newItemTemplate, authentication, templateDictionary) {
|
|
1191
|
-
return new Promise(
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1332
|
+
return new Promise((resolve, reject) => {
|
|
1333
|
+
const serviceInfo = newItemTemplate.properties;
|
|
1334
|
+
const folderId = templateDictionary.folderId;
|
|
1335
|
+
const isPortal = templateDictionary.isPortal;
|
|
1336
|
+
const itemId = newItemTemplate.itemId;
|
|
1196
1337
|
validateSpatialReferenceAndExtent(serviceInfo, newItemTemplate, templateDictionary);
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1338
|
+
const fallbackExtent = _getFallbackExtent(serviceInfo, templateDictionary);
|
|
1339
|
+
const params = {};
|
|
1340
|
+
const itemInfo = {
|
|
1200
1341
|
title: newItemTemplate.item.title,
|
|
1201
1342
|
name: newItemTemplate.item.name
|
|
1202
1343
|
};
|
|
1203
|
-
|
|
1204
|
-
|
|
1344
|
+
const _item = {
|
|
1345
|
+
...itemInfo,
|
|
1346
|
+
preserveLayerIds: true
|
|
1347
|
+
};
|
|
1348
|
+
const createOptions = {
|
|
1205
1349
|
item: _item,
|
|
1206
|
-
folderId
|
|
1207
|
-
params
|
|
1350
|
+
folderId,
|
|
1351
|
+
params,
|
|
1208
1352
|
authentication: authentication
|
|
1209
1353
|
};
|
|
1210
|
-
createOptions.item =
|
|
1354
|
+
createOptions.item = !isTrackingViewTemplate(newItemTemplate) ?
|
|
1355
|
+
_setItemProperties(createOptions.item, newItemTemplate, serviceInfo, params, isPortal) :
|
|
1356
|
+
setTrackingOptions(newItemTemplate, createOptions, templateDictionary);
|
|
1211
1357
|
// project the portals extent to match that of the service
|
|
1212
|
-
convertExtentWithFallback(templateDictionary.organization.defaultExtent, fallbackExtent, serviceInfo.service.spatialReference, templateDictionary.organization.helperServices.geometry.url, authentication).then(
|
|
1358
|
+
convertExtentWithFallback(templateDictionary.organization.defaultExtent, fallbackExtent, serviceInfo.service.spatialReference, templateDictionary.organization.helperServices.geometry.url, authentication).then(extent => {
|
|
1213
1359
|
templateDictionary[itemId].solutionExtent = extent;
|
|
1214
1360
|
setDefaultSpatialReference(templateDictionary, itemId, extent.spatialReference);
|
|
1215
1361
|
createOptions.item = replaceInTemplate(createOptions.item, templateDictionary);
|
|
@@ -1219,7 +1365,7 @@ export function _getCreateServiceOptions(newItemTemplate, authentication, templa
|
|
|
1219
1365
|
createOptions.params.thumbnail = newItemTemplate.item.thumbnail;
|
|
1220
1366
|
}
|
|
1221
1367
|
resolve(createOptions);
|
|
1222
|
-
},
|
|
1368
|
+
}, e => reject(fail(e)));
|
|
1223
1369
|
});
|
|
1224
1370
|
}
|
|
1225
1371
|
/**
|
|
@@ -1235,9 +1381,9 @@ export function _getCreateServiceOptions(newItemTemplate, authentication, templa
|
|
|
1235
1381
|
* @private
|
|
1236
1382
|
*/
|
|
1237
1383
|
export function _getFallbackExtent(serviceInfo, templateDictionary) {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1384
|
+
const serviceSR = serviceInfo.service.spatialReference;
|
|
1385
|
+
const serviceInfoWkid = getProp(serviceInfo, "defaultExtent.spatialReference.wkid");
|
|
1386
|
+
const customDefaultExtent = getProp(templateDictionary, "params.defaultExtent");
|
|
1241
1387
|
return serviceInfoWkid && serviceInfoWkid === serviceSR.wkid
|
|
1242
1388
|
? serviceInfo.defaultExtent
|
|
1243
1389
|
: customDefaultExtent
|
|
@@ -1252,11 +1398,11 @@ export function _getFallbackExtent(serviceInfo, templateDictionary) {
|
|
|
1252
1398
|
* @private
|
|
1253
1399
|
*/
|
|
1254
1400
|
export function _getRelationshipUpdates(args) {
|
|
1255
|
-
|
|
1401
|
+
const rels = {
|
|
1256
1402
|
layers: []
|
|
1257
1403
|
};
|
|
1258
|
-
Object.keys(args.objects).forEach(
|
|
1259
|
-
|
|
1404
|
+
Object.keys(args.objects).forEach((k) => {
|
|
1405
|
+
const obj = args.objects[k];
|
|
1260
1406
|
/* istanbul ignore else */
|
|
1261
1407
|
if (obj.relationships && obj.relationships.length > 0) {
|
|
1262
1408
|
rels.layers.push({
|
|
@@ -1280,7 +1426,7 @@ export function _getRelationshipUpdates(args) {
|
|
|
1280
1426
|
* @private
|
|
1281
1427
|
*/
|
|
1282
1428
|
export function _getUpdate(url, id, obj, args, type) {
|
|
1283
|
-
|
|
1429
|
+
const ops = {
|
|
1284
1430
|
delete: {
|
|
1285
1431
|
url: checkUrlPathTermination(url) + id + "/deleteFromDefinition",
|
|
1286
1432
|
params: {
|
|
@@ -1291,7 +1437,7 @@ export function _getUpdate(url, id, obj, args, type) {
|
|
|
1291
1437
|
},
|
|
1292
1438
|
update: {
|
|
1293
1439
|
url: checkUrlPathTermination(url) +
|
|
1294
|
-
(id ? id
|
|
1440
|
+
(id ? `${id}/updateDefinition` : "updateDefinition"),
|
|
1295
1441
|
params: {
|
|
1296
1442
|
updateDefinition: obj
|
|
1297
1443
|
}
|
|
@@ -1322,7 +1468,7 @@ export function _getUpdate(url, id, obj, args, type) {
|
|
|
1322
1468
|
* @param data Item's data section
|
|
1323
1469
|
*/
|
|
1324
1470
|
export function _reportVariablesInItem(itemId, itemType, base, data) {
|
|
1325
|
-
|
|
1471
|
+
const getUnresolved = (v) => {
|
|
1326
1472
|
return JSON.stringify(v).match(/{{.+?}}/gim);
|
|
1327
1473
|
};
|
|
1328
1474
|
// Provide feedback about any remaining unresolved variables
|
|
@@ -1347,14 +1493,15 @@ export function _reportVariablesInItem(itemId, itemType, base, data) {
|
|
|
1347
1493
|
* Updates a feature service item.
|
|
1348
1494
|
*
|
|
1349
1495
|
* @param item Item to update
|
|
1496
|
+
* @param itemTemplate item template for the new item
|
|
1350
1497
|
* @param serviceInfo Service information
|
|
1351
1498
|
* @param params arcgis-rest-js params to update
|
|
1352
1499
|
* @param isPortal Is the service hosted in a portal?
|
|
1353
1500
|
* @return Updated item
|
|
1354
1501
|
*/
|
|
1355
|
-
export function _setItemProperties(item, serviceInfo, params, isPortal) {
|
|
1502
|
+
export function _setItemProperties(item, itemTemplate, serviceInfo, params, isPortal) {
|
|
1356
1503
|
// Set the capabilities
|
|
1357
|
-
|
|
1504
|
+
const portalCapabilities = [
|
|
1358
1505
|
"Create",
|
|
1359
1506
|
"Query",
|
|
1360
1507
|
"Editing",
|
|
@@ -1364,11 +1511,11 @@ export function _setItemProperties(item, serviceInfo, params, isPortal) {
|
|
|
1364
1511
|
"Sync",
|
|
1365
1512
|
"Extract"
|
|
1366
1513
|
];
|
|
1367
|
-
|
|
1514
|
+
const capabilities = getProp(serviceInfo, "service.capabilities") || (isPortal ? "" : []);
|
|
1368
1515
|
item.capabilities = isPortal
|
|
1369
1516
|
? capabilities
|
|
1370
1517
|
.split(",")
|
|
1371
|
-
.filter(
|
|
1518
|
+
.filter((c) => portalCapabilities.indexOf(c) > -1)
|
|
1372
1519
|
.join(",")
|
|
1373
1520
|
: capabilities;
|
|
1374
1521
|
if (serviceInfo.service.capabilities) {
|
|
@@ -1378,22 +1525,22 @@ export function _setItemProperties(item, serviceInfo, params, isPortal) {
|
|
|
1378
1525
|
// have non-unique indexes on relationship key fields
|
|
1379
1526
|
_updateIndexesForRelationshipKeyFields(serviceInfo);
|
|
1380
1527
|
// set create options item properties
|
|
1381
|
-
|
|
1528
|
+
const keyProperties = [
|
|
1382
1529
|
"isView",
|
|
1383
1530
|
"sourceSchemaChangesAllowed",
|
|
1384
1531
|
"isUpdatableView",
|
|
1385
1532
|
"capabilities",
|
|
1386
1533
|
"isMultiServicesView"
|
|
1387
1534
|
];
|
|
1388
|
-
|
|
1535
|
+
const deleteKeys = ["layers", "tables"];
|
|
1389
1536
|
/* istanbul ignore else */
|
|
1390
1537
|
if (isPortal) {
|
|
1391
1538
|
// removed for issue #423 causing FS to fail to create
|
|
1392
1539
|
deleteKeys.push("adminServiceInfo");
|
|
1393
1540
|
}
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
serviceKeys.forEach(
|
|
1541
|
+
const itemKeys = Object.keys(item);
|
|
1542
|
+
const serviceKeys = Object.keys(serviceInfo.service);
|
|
1543
|
+
serviceKeys.forEach(k => {
|
|
1397
1544
|
/* istanbul ignore else */
|
|
1398
1545
|
if (itemKeys.indexOf(k) === -1 && deleteKeys.indexOf(k) < 0) {
|
|
1399
1546
|
item[k] = serviceInfo.service[k];
|
|
@@ -1431,16 +1578,16 @@ export function _setItemProperties(item, serviceInfo, params, isPortal) {
|
|
|
1431
1578
|
* @protected
|
|
1432
1579
|
*/
|
|
1433
1580
|
export function _updateIndexesForRelationshipKeyFields(serviceInfo) {
|
|
1434
|
-
|
|
1435
|
-
layersAndTables.forEach(
|
|
1436
|
-
|
|
1437
|
-
|
|
1581
|
+
const layersAndTables = (serviceInfo.layers || []).concat(serviceInfo.tables || []);
|
|
1582
|
+
layersAndTables.forEach(item => {
|
|
1583
|
+
const relationships = item.relationships;
|
|
1584
|
+
const indexes = item.indexes;
|
|
1438
1585
|
/* istanbul ignore else */
|
|
1439
1586
|
if (relationships &&
|
|
1440
1587
|
relationships.length > 0 &&
|
|
1441
1588
|
indexes &&
|
|
1442
1589
|
indexes.length > 0) {
|
|
1443
|
-
|
|
1590
|
+
const keyFields = relationships.reduce((acc, v) => {
|
|
1444
1591
|
/* istanbul ignore else */
|
|
1445
1592
|
if (v.role === "esriRelRoleOrigin" &&
|
|
1446
1593
|
v.keyField &&
|
|
@@ -1449,10 +1596,10 @@ export function _updateIndexesForRelationshipKeyFields(serviceInfo) {
|
|
|
1449
1596
|
}
|
|
1450
1597
|
return acc;
|
|
1451
1598
|
}, []);
|
|
1452
|
-
indexes.map(
|
|
1599
|
+
indexes.map(i => {
|
|
1453
1600
|
/* istanbul ignore else */
|
|
1454
|
-
if (
|
|
1455
|
-
|
|
1601
|
+
if (keyFields.some(k => {
|
|
1602
|
+
const regEx = new RegExp(`\\b${k}\\b`);
|
|
1456
1603
|
return regEx.test(i.fields);
|
|
1457
1604
|
})) {
|
|
1458
1605
|
i.isUnique = true;
|
|
@@ -1472,23 +1619,22 @@ export function _updateIndexesForRelationshipKeyFields(serviceInfo) {
|
|
|
1472
1619
|
* @return A promise that will resolve with the item id when the item has been updated or an AGO-style JSON failure
|
|
1473
1620
|
* response
|
|
1474
1621
|
*/
|
|
1475
|
-
export function _updateItemURL(id, url, authentication, numAttempts) {
|
|
1476
|
-
if (numAttempts === void 0) { numAttempts = 1; }
|
|
1622
|
+
export function _updateItemURL(id, url, authentication, numAttempts = 1) {
|
|
1477
1623
|
// Introduce a lag because AGO update appears to choke with rapid subsequent calls
|
|
1478
|
-
|
|
1479
|
-
return new Promise(
|
|
1624
|
+
const msLag = 1000;
|
|
1625
|
+
return new Promise((resolve, reject) => {
|
|
1480
1626
|
// Update the item's URL
|
|
1481
|
-
|
|
1482
|
-
portalUpdateItem(options).then(
|
|
1627
|
+
const options = { item: { id, url }, authentication: authentication };
|
|
1628
|
+
portalUpdateItem(options).then(result => {
|
|
1483
1629
|
if (!result.success) {
|
|
1484
1630
|
reject(fail(result));
|
|
1485
1631
|
}
|
|
1486
1632
|
else {
|
|
1487
1633
|
// Get the item to see if the URL really changed; we'll delay a bit before testing because AGO
|
|
1488
1634
|
// has a timing problem with URL updates
|
|
1489
|
-
setTimeout(
|
|
1490
|
-
getItem(id, { authentication: authentication }).then(
|
|
1491
|
-
|
|
1635
|
+
setTimeout(() => {
|
|
1636
|
+
getItem(id, { authentication: authentication }).then(item => {
|
|
1637
|
+
const iBrace = item.url.indexOf("{");
|
|
1492
1638
|
if (iBrace > -1) {
|
|
1493
1639
|
console.warn(id + " has template variable: " + item.url.substr(iBrace));
|
|
1494
1640
|
}
|
|
@@ -1497,7 +1643,7 @@ export function _updateItemURL(id, url, authentication, numAttempts) {
|
|
|
1497
1643
|
}
|
|
1498
1644
|
else {
|
|
1499
1645
|
// If it fails, try again if we have sufficient attempts remaining
|
|
1500
|
-
|
|
1646
|
+
const errorMsg = "URL not updated for " +
|
|
1501
1647
|
item.type +
|
|
1502
1648
|
" " +
|
|
1503
1649
|
item.id +
|
|
@@ -1514,10 +1660,10 @@ export function _updateItemURL(id, url, authentication, numAttempts) {
|
|
|
1514
1660
|
reject(errorMsg);
|
|
1515
1661
|
}
|
|
1516
1662
|
}
|
|
1517
|
-
},
|
|
1663
|
+
}, e => reject(fail(e)));
|
|
1518
1664
|
}, msLag);
|
|
1519
1665
|
}
|
|
1520
|
-
},
|
|
1666
|
+
}, e => reject(fail(e)));
|
|
1521
1667
|
});
|
|
1522
1668
|
}
|
|
1523
1669
|
//# sourceMappingURL=restHelpers.js.map
|