@esri/solution-common 5.2.3 → 5.2.4

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 (192) hide show
  1. package/dist/cjs/completeItem.d.ts +29 -0
  2. package/dist/cjs/completeItem.js +92 -0
  3. package/dist/cjs/completeItem.js.map +1 -0
  4. package/dist/cjs/create-hub-request-options.d.ts +29 -0
  5. package/dist/cjs/create-hub-request-options.js +64 -0
  6. package/dist/cjs/create-hub-request-options.js.map +1 -0
  7. package/dist/cjs/deleteHelpers/deleteEmptyGroups.d.ts +24 -0
  8. package/dist/cjs/deleteHelpers/deleteEmptyGroups.js +42 -0
  9. package/dist/cjs/deleteHelpers/deleteEmptyGroups.js.map +1 -0
  10. package/dist/cjs/deleteHelpers/deleteGroupIfEmpty.d.ts +27 -0
  11. package/dist/cjs/deleteHelpers/deleteGroupIfEmpty.js +97 -0
  12. package/dist/cjs/deleteHelpers/deleteGroupIfEmpty.js.map +1 -0
  13. package/dist/cjs/deleteHelpers/deleteSolutionContents.d.ts +38 -0
  14. package/dist/cjs/deleteHelpers/deleteSolutionContents.js +130 -0
  15. package/dist/cjs/deleteHelpers/deleteSolutionContents.js.map +1 -0
  16. package/dist/cjs/deleteHelpers/deleteSolutionFolder.d.ts +29 -0
  17. package/dist/cjs/deleteHelpers/deleteSolutionFolder.js +79 -0
  18. package/dist/cjs/deleteHelpers/deleteSolutionFolder.js.map +1 -0
  19. package/dist/cjs/deleteHelpers/deleteSolutionItem.d.ts +30 -0
  20. package/dist/cjs/deleteHelpers/deleteSolutionItem.js +54 -0
  21. package/dist/cjs/deleteHelpers/deleteSolutionItem.js.map +1 -0
  22. package/dist/cjs/deleteHelpers/index.d.ts +22 -0
  23. package/dist/cjs/deleteHelpers/index.js +26 -0
  24. package/dist/cjs/deleteHelpers/index.js.map +1 -0
  25. package/dist/cjs/deleteHelpers/reconstructBuildOrderIds.d.ts +27 -0
  26. package/dist/cjs/deleteHelpers/reconstructBuildOrderIds.js +34 -0
  27. package/dist/cjs/deleteHelpers/reconstructBuildOrderIds.js.map +1 -0
  28. package/dist/cjs/deleteHelpers/removeItems.d.ts +34 -0
  29. package/dist/cjs/deleteHelpers/removeItems.js +112 -0
  30. package/dist/cjs/deleteHelpers/removeItems.js.map +1 -0
  31. package/dist/cjs/deleteHelpers/reportProgress.d.ts +27 -0
  32. package/dist/cjs/deleteHelpers/reportProgress.js +46 -0
  33. package/dist/cjs/deleteHelpers/reportProgress.js.map +1 -0
  34. package/dist/cjs/deleteSolution.d.ts +55 -0
  35. package/dist/cjs/deleteSolution.js +107 -0
  36. package/dist/cjs/deleteSolution.js.map +1 -0
  37. package/dist/cjs/dependencies.d.ts +26 -0
  38. package/dist/cjs/dependencies.js +171 -0
  39. package/dist/cjs/dependencies.js.map +1 -0
  40. package/dist/cjs/featureServiceHelpers.d.ts +799 -0
  41. package/dist/cjs/featureServiceHelpers.js +2438 -0
  42. package/dist/cjs/featureServiceHelpers.js.map +1 -0
  43. package/dist/cjs/formHelpers.d.ts +41 -0
  44. package/dist/cjs/formHelpers.js +78 -0
  45. package/dist/cjs/formHelpers.js.map +1 -0
  46. package/dist/cjs/generalHelpers.d.ts +433 -0
  47. package/dist/cjs/generalHelpers.js +925 -0
  48. package/dist/cjs/generalHelpers.js.map +1 -0
  49. package/dist/cjs/get-subscription-info.d.ts +27 -0
  50. package/dist/cjs/get-subscription-info.js +39 -0
  51. package/dist/cjs/get-subscription-info.js.map +1 -0
  52. package/dist/cjs/getDeletableSolutionInfo.d.ts +29 -0
  53. package/dist/cjs/getDeletableSolutionInfo.js +53 -0
  54. package/dist/cjs/getDeletableSolutionInfo.js.map +1 -0
  55. package/dist/cjs/getItemTypeAbbrev.d.ts +19 -0
  56. package/dist/cjs/getItemTypeAbbrev.js +186 -0
  57. package/dist/cjs/getItemTypeAbbrev.js.map +1 -0
  58. package/dist/cjs/getSolutionSummary.d.ts +27 -0
  59. package/dist/cjs/getSolutionSummary.js +101 -0
  60. package/dist/cjs/getSolutionSummary.js.map +1 -0
  61. package/dist/cjs/index.d.ts +46 -0
  62. package/dist/cjs/index.js +50 -0
  63. package/dist/cjs/index.js.map +1 -0
  64. package/dist/cjs/interfaces.d.ts +1362 -0
  65. package/dist/cjs/interfaces.js +77 -0
  66. package/dist/cjs/interfaces.js.map +1 -0
  67. package/dist/cjs/libConnectors.d.ts +73 -0
  68. package/dist/cjs/libConnectors.js +115 -0
  69. package/dist/cjs/libConnectors.js.map +1 -0
  70. package/dist/cjs/migrations/apply-schema.d.ts +24 -0
  71. package/dist/cjs/migrations/apply-schema.js +36 -0
  72. package/dist/cjs/migrations/apply-schema.js.map +1 -0
  73. package/dist/cjs/migrations/is-legacy-solution.d.ts +24 -0
  74. package/dist/cjs/migrations/is-legacy-solution.js +40 -0
  75. package/dist/cjs/migrations/is-legacy-solution.js.map +1 -0
  76. package/dist/cjs/migrations/upgrade-three-dot-one.d.ts +27 -0
  77. package/dist/cjs/migrations/upgrade-three-dot-one.js +49 -0
  78. package/dist/cjs/migrations/upgrade-three-dot-one.js.map +1 -0
  79. package/dist/cjs/migrations/upgrade-three-dot-zero.d.ts +27 -0
  80. package/dist/cjs/migrations/upgrade-three-dot-zero.js +43 -0
  81. package/dist/cjs/migrations/upgrade-three-dot-zero.js.map +1 -0
  82. package/dist/cjs/migrations/upgrade-two-dot-five.d.ts +24 -0
  83. package/dist/cjs/migrations/upgrade-two-dot-five.js +73 -0
  84. package/dist/cjs/migrations/upgrade-two-dot-five.js.map +1 -0
  85. package/dist/cjs/migrations/upgrade-two-dot-four.d.ts +24 -0
  86. package/dist/cjs/migrations/upgrade-two-dot-four.js +72 -0
  87. package/dist/cjs/migrations/upgrade-two-dot-four.js.map +1 -0
  88. package/dist/cjs/migrations/upgrade-two-dot-one.d.ts +7 -0
  89. package/dist/cjs/migrations/upgrade-two-dot-one.js +39 -0
  90. package/dist/cjs/migrations/upgrade-two-dot-one.js.map +1 -0
  91. package/dist/cjs/migrations/upgrade-two-dot-seven.d.ts +23 -0
  92. package/dist/cjs/migrations/upgrade-two-dot-seven.js +58 -0
  93. package/dist/cjs/migrations/upgrade-two-dot-seven.js.map +1 -0
  94. package/dist/cjs/migrations/upgrade-two-dot-six.d.ts +27 -0
  95. package/dist/cjs/migrations/upgrade-two-dot-six.js +61 -0
  96. package/dist/cjs/migrations/upgrade-two-dot-six.js.map +1 -0
  97. package/dist/cjs/migrations/upgrade-two-dot-three.d.ts +23 -0
  98. package/dist/cjs/migrations/upgrade-two-dot-three.js +55 -0
  99. package/dist/cjs/migrations/upgrade-two-dot-three.js.map +1 -0
  100. package/dist/cjs/migrations/upgrade-two-dot-two.d.ts +23 -0
  101. package/dist/cjs/migrations/upgrade-two-dot-two.js +58 -0
  102. package/dist/cjs/migrations/upgrade-two-dot-two.js.map +1 -0
  103. package/dist/cjs/migrations/upgrade-two-dot-zero.d.ts +44 -0
  104. package/dist/cjs/migrations/upgrade-two-dot-zero.js +95 -0
  105. package/dist/cjs/migrations/upgrade-two-dot-zero.js.map +1 -0
  106. package/dist/cjs/migrator.d.ts +25 -0
  107. package/dist/cjs/migrator.js +77 -0
  108. package/dist/cjs/migrator.js.map +1 -0
  109. package/dist/cjs/package.json +3 -0
  110. package/dist/cjs/resourceHelpers.d.ts +191 -0
  111. package/dist/cjs/resourceHelpers.js +384 -0
  112. package/dist/cjs/resourceHelpers.js.map +1 -0
  113. package/dist/cjs/resources/add-resource-from-blob.d.ts +26 -0
  114. package/dist/cjs/resources/add-resource-from-blob.js +52 -0
  115. package/dist/cjs/resources/add-resource-from-blob.js.map +1 -0
  116. package/dist/cjs/resources/addMetadataFromBlob.d.ts +25 -0
  117. package/dist/cjs/resources/addMetadataFromBlob.js +43 -0
  118. package/dist/cjs/resources/addMetadataFromBlob.js.map +1 -0
  119. package/dist/cjs/resources/convert-item-resource-to-storage-resource.d.ts +32 -0
  120. package/dist/cjs/resources/convert-item-resource-to-storage-resource.js +70 -0
  121. package/dist/cjs/resources/convert-item-resource-to-storage-resource.js.map +1 -0
  122. package/dist/cjs/resources/convert-storage-resource-to-item-resource.d.ts +29 -0
  123. package/dist/cjs/resources/convert-storage-resource-to-item-resource.js +70 -0
  124. package/dist/cjs/resources/convert-storage-resource-to-item-resource.js.map +1 -0
  125. package/dist/cjs/resources/copyAssociatedFiles.d.ts +67 -0
  126. package/dist/cjs/resources/copyAssociatedFiles.js +304 -0
  127. package/dist/cjs/resources/copyAssociatedFiles.js.map +1 -0
  128. package/dist/cjs/resources/copyDataIntoItem.d.ts +33 -0
  129. package/dist/cjs/resources/copyDataIntoItem.js +62 -0
  130. package/dist/cjs/resources/copyDataIntoItem.js.map +1 -0
  131. package/dist/cjs/resources/copyMetadataIntoItem.d.ts +26 -0
  132. package/dist/cjs/resources/copyMetadataIntoItem.js +46 -0
  133. package/dist/cjs/resources/copyMetadataIntoItem.js.map +1 -0
  134. package/dist/cjs/resources/copyResourceIntoZip.d.ts +33 -0
  135. package/dist/cjs/resources/copyResourceIntoZip.js +78 -0
  136. package/dist/cjs/resources/copyResourceIntoZip.js.map +1 -0
  137. package/dist/cjs/resources/copyZipIntoItem.d.ts +25 -0
  138. package/dist/cjs/resources/copyZipIntoItem.js +54 -0
  139. package/dist/cjs/resources/copyZipIntoItem.js.map +1 -0
  140. package/dist/cjs/resources/createCopyResults.d.ts +25 -0
  141. package/dist/cjs/resources/createCopyResults.js +36 -0
  142. package/dist/cjs/resources/createCopyResults.js.map +1 -0
  143. package/dist/cjs/resources/get-blob.d.ts +26 -0
  144. package/dist/cjs/resources/get-blob.js +27 -0
  145. package/dist/cjs/resources/get-blob.js.map +1 -0
  146. package/dist/cjs/resources/getItemResourcesFilesFromPaths.d.ts +24 -0
  147. package/dist/cjs/resources/getItemResourcesFilesFromPaths.js +49 -0
  148. package/dist/cjs/resources/getItemResourcesFilesFromPaths.js.map +1 -0
  149. package/dist/cjs/resources/getItemResourcesPaths.d.ts +26 -0
  150. package/dist/cjs/resources/getItemResourcesPaths.js +76 -0
  151. package/dist/cjs/resources/getItemResourcesPaths.js.map +1 -0
  152. package/dist/cjs/resources/index.d.ts +29 -0
  153. package/dist/cjs/resources/index.js +33 -0
  154. package/dist/cjs/resources/index.js.map +1 -0
  155. package/dist/cjs/resources/solution-resource.d.ts +35 -0
  156. package/dist/cjs/resources/solution-resource.js +31 -0
  157. package/dist/cjs/resources/solution-resource.js.map +1 -0
  158. package/dist/cjs/resources/transform-resource-paths-to-solution-resources.d.ts +56 -0
  159. package/dist/cjs/resources/transform-resource-paths-to-solution-resources.js +146 -0
  160. package/dist/cjs/resources/transform-resource-paths-to-solution-resources.js.map +1 -0
  161. package/dist/cjs/restHelpers.d.ts +607 -0
  162. package/dist/cjs/restHelpers.js +1954 -0
  163. package/dist/cjs/restHelpers.js.map +1 -0
  164. package/dist/cjs/restHelpersGet.d.ts +288 -0
  165. package/dist/cjs/restHelpersGet.js +804 -0
  166. package/dist/cjs/restHelpersGet.js.map +1 -0
  167. package/dist/cjs/sharing/index.d.ts +16 -0
  168. package/dist/cjs/sharing/index.js +20 -0
  169. package/dist/cjs/sharing/index.js.map +1 -0
  170. package/dist/cjs/sharing/share-item-to-groups.d.ts +26 -0
  171. package/dist/cjs/sharing/share-item-to-groups.js +44 -0
  172. package/dist/cjs/sharing/share-item-to-groups.js.map +1 -0
  173. package/dist/cjs/templatization.d.ts +139 -0
  174. package/dist/cjs/templatization.js +316 -0
  175. package/dist/cjs/templatization.js.map +1 -0
  176. package/dist/cjs/trackingHelpers.d.ts +116 -0
  177. package/dist/cjs/trackingHelpers.js +217 -0
  178. package/dist/cjs/trackingHelpers.js.map +1 -0
  179. package/dist/cjs/velocityHelpers.d.ts +57 -0
  180. package/dist/cjs/velocityHelpers.js +135 -0
  181. package/dist/cjs/velocityHelpers.js.map +1 -0
  182. package/dist/cjs/workflowHelpers.d.ts +37 -0
  183. package/dist/cjs/workflowHelpers.js +77 -0
  184. package/dist/cjs/workflowHelpers.js.map +1 -0
  185. package/dist/cjs/workforceHelpers.d.ts +115 -0
  186. package/dist/cjs/workforceHelpers.js +749 -0
  187. package/dist/cjs/workforceHelpers.js.map +1 -0
  188. package/dist/cjs/zip-utils.d.ts +76 -0
  189. package/dist/cjs/zip-utils.js +142 -0
  190. package/dist/cjs/zip-utils.js.map +1 -0
  191. package/dist/esm/package.json +3 -0
  192. package/package.json +2 -2
@@ -0,0 +1,749 @@
1
+ "use strict";
2
+ /** @license
3
+ * Copyright 2020 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._applyEdits = exports._updateDispatchers = exports._getField = exports._getAddFeatures = exports._updateUrl = exports._getFields = exports.fineTuneCreatedWorkforceItem = exports._getURLs = exports.urlTest = exports.getKeyWorkforceProperties = exports.isWorkforceProject = exports._templatizeWorkforceDispatcherOrWorker = exports._templatizeWorkforceProject = exports.postProcessWorkforceTemplates = exports.getReplaceValue = exports.getLayerId = exports._templatizeUrlTemplate = exports.getUrlDependencies = exports._getAssignmentIntegrationInfos = exports._getAssignmentTypeInfos = exports._updateGlobalIdAndAssignmentType = exports.getWorkforceServiceInfo = exports.getWorkforceDependencies = exports.templatizeWorkforce = exports.extractWorkforceDependencies = exports.convertWorkforceItemToTemplate = void 0;
19
+ /**
20
+ * Provides general helper functions.
21
+ *
22
+ * @module workforceHelpers
23
+ */
24
+ const arcgis_rest_feature_layer_1 = require("@esri/arcgis-rest-feature-layer");
25
+ const generalHelpers_1 = require("./generalHelpers");
26
+ const restHelpers_1 = require("./restHelpers");
27
+ const templatization_1 = require("./templatization");
28
+ const featureServiceHelpers_1 = require("./featureServiceHelpers");
29
+ //#region workforce v1
30
+ /**
31
+ * Converts an workforce item to a template.
32
+ *
33
+ * @param itemTemplate template for the workforce project item
34
+ * @param authentication credentials for any requests
35
+ * @param templateDictionary Hash of key details used for variable replacement
36
+ * @returns templatized itemTemplate
37
+ */
38
+ function convertWorkforceItemToTemplate(itemTemplate, authentication, templateDictionary) {
39
+ return new Promise((resolve, reject) => {
40
+ // This function is specific to workforce v1 project structure
41
+ // Key properties that contain item IDs for the workforce project type
42
+ const keyProperties = getKeyWorkforceProperties(1);
43
+ // The templates data to process
44
+ const data = itemTemplate.data;
45
+ if (data) {
46
+ // Extract dependencies
47
+ extractWorkforceDependencies(data, keyProperties, authentication).then(results => {
48
+ itemTemplate.dependencies = results.dependencies;
49
+ // templatize key properties
50
+ itemTemplate.data = templatizeWorkforce(data, keyProperties, results.urlHash, templateDictionary);
51
+ resolve(itemTemplate);
52
+ }, e => reject((0, generalHelpers_1.fail)(e)));
53
+ }
54
+ else {
55
+ resolve(itemTemplate);
56
+ }
57
+ });
58
+ }
59
+ exports.convertWorkforceItemToTemplate = convertWorkforceItemToTemplate;
60
+ /**
61
+ * Gets the ids of the dependencies of the workforce project.
62
+ *
63
+ * @param data itemTemplate data
64
+ * @param keyProperties workforce project properties that contain references to dependencies
65
+ * @param authentication credentials for any requests
66
+ * @returns List of dependencies ids
67
+ */
68
+ function extractWorkforceDependencies(data, keyProperties, authentication) {
69
+ return new Promise((resolve, reject) => {
70
+ const deps = [];
71
+ // get the ids for the service dependencies
72
+ // "workerWebMapId" and "dispatcherWebMapId" are already IDs and don't have a serviceItemId
73
+ keyProperties.forEach(p => {
74
+ const serviceItemId = (0, generalHelpers_1.getProp)(data, p + ".serviceItemId");
75
+ const v = (0, generalHelpers_1.getProp)(data, p);
76
+ if (serviceItemId) {
77
+ if (deps.indexOf(serviceItemId) === -1) {
78
+ deps.push(serviceItemId);
79
+ }
80
+ }
81
+ else {
82
+ (0, generalHelpers_1.idTest)(v, deps);
83
+ }
84
+ });
85
+ if ((0, generalHelpers_1.getProp)(data, "assignmentIntegrations")) {
86
+ let requests = [];
87
+ let urls = [];
88
+ data.assignmentIntegrations.forEach((ai) => {
89
+ if (ai.assignmentTypes) {
90
+ const assignmentKeys = Object.keys(ai.assignmentTypes);
91
+ assignmentKeys.forEach(k => {
92
+ const urlTemplate = ai.assignmentTypes[k].urlTemplate;
93
+ (0, generalHelpers_1.idTest)(urlTemplate, deps);
94
+ const serviceRequests = urlTest(urlTemplate, authentication);
95
+ if (Array.isArray(serviceRequests.requests) &&
96
+ serviceRequests.requests.length > 0) {
97
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
98
+ requests = requests.concat(serviceRequests.requests);
99
+ urls = urls.concat(serviceRequests.urls);
100
+ }
101
+ });
102
+ }
103
+ });
104
+ if (requests.length > 0) {
105
+ Promise.all(requests).then(results => {
106
+ const urlHash = {};
107
+ // Get the serviceItemId for the url
108
+ /* istanbul ignore else */
109
+ if (Array.isArray(results)) {
110
+ results.forEach((result, i) => {
111
+ /* istanbul ignore else */
112
+ if (result.serviceItemId) {
113
+ urlHash[urls[i]] = result.serviceItemId;
114
+ /* istanbul ignore else */
115
+ if (deps.indexOf(result.serviceItemId) === -1) {
116
+ deps.push(result.serviceItemId);
117
+ }
118
+ }
119
+ });
120
+ }
121
+ resolve({
122
+ dependencies: deps,
123
+ urlHash: urlHash
124
+ });
125
+ }, e => reject((0, generalHelpers_1.fail)(e)));
126
+ }
127
+ else {
128
+ resolve({
129
+ dependencies: deps,
130
+ urlHash: {}
131
+ });
132
+ }
133
+ }
134
+ else {
135
+ resolve({
136
+ dependencies: deps,
137
+ urlHash: {}
138
+ });
139
+ }
140
+ });
141
+ }
142
+ exports.extractWorkforceDependencies = extractWorkforceDependencies;
143
+ /**
144
+ * Templatizes key item properties.
145
+ *
146
+ * @param data itemTemplate data
147
+ * @param keyProperties workforce project properties that should be templatized
148
+ * @param urlHash a key value pair of url and itemId
149
+ * @param templateDictionary Hash of key details used for variable replacement
150
+ * @returns an updated data object to be stored in the template
151
+ */
152
+ function templatizeWorkforce(data, keyProperties, urlHash, templateDictionary) {
153
+ keyProperties.forEach(p => {
154
+ /* istanbul ignore else */
155
+ if ((0, generalHelpers_1.getProp)(data, p)) {
156
+ if ((0, generalHelpers_1.getProp)(data[p], "serviceItemId")) {
157
+ // templatize properties with id and url
158
+ const id = data[p].serviceItemId;
159
+ let serviceItemIdSuffix = ".itemId";
160
+ /* istanbul ignore else */
161
+ if ((0, generalHelpers_1.getProp)(data[p], "url")) {
162
+ const layerId = getLayerId(data[p].url);
163
+ (0, featureServiceHelpers_1.cacheLayerInfo)(layerId, id, data[p].url, templateDictionary);
164
+ data[p].url = (0, templatization_1.templatizeTerm)(id, id, getReplaceValue(layerId, ".url"));
165
+ serviceItemIdSuffix = getReplaceValue(layerId, serviceItemIdSuffix);
166
+ }
167
+ data[p].serviceItemId = (0, templatization_1.templatizeTerm)(id, id, serviceItemIdSuffix);
168
+ }
169
+ else {
170
+ // templatize simple id properties
171
+ data[p] = (0, templatization_1.templatizeTerm)(data[p], data[p], ".itemId");
172
+ }
173
+ }
174
+ });
175
+ data["folderId"] = "{{folderId}}";
176
+ // templatize app integrations
177
+ const integrations = data.assignmentIntegrations || [];
178
+ integrations.forEach(i => {
179
+ _templatizeUrlTemplate(i, urlHash);
180
+ /* istanbul ignore else */
181
+ if (i.assignmentTypes) {
182
+ const assignmentKeys = Object.keys(i.assignmentTypes);
183
+ assignmentKeys.forEach(k => {
184
+ _templatizeUrlTemplate(i.assignmentTypes[k], urlHash);
185
+ });
186
+ }
187
+ });
188
+ return data;
189
+ }
190
+ exports.templatizeWorkforce = templatizeWorkforce;
191
+ //#endregion
192
+ /**
193
+ * Evaluate key properties in the workforce service of additional items that are needed
194
+ *
195
+ * @param itemTemplate template for the workforce project item
196
+ * @param dependencies list of the items dependencies
197
+ * @returns an array of objects with dependency ids
198
+ */
199
+ function getWorkforceDependencies(itemTemplate, dependencies) {
200
+ const properties = itemTemplate.item.properties || {};
201
+ const keyProperties = getKeyWorkforceProperties(2);
202
+ dependencies = keyProperties.reduce(function (acc, v) {
203
+ /* istanbul ignore else */
204
+ if (properties[v] && dependencies.indexOf(properties[v]) < 0) {
205
+ acc.push(properties[v]);
206
+ }
207
+ return acc;
208
+ }, dependencies);
209
+ // We also need the dependencies listed in the Assignment Integrations table
210
+ const infos = (0, generalHelpers_1.getProp)(itemTemplate, "properties.workforceInfos.assignmentIntegrationInfos");
211
+ /* istanbul ignore else */
212
+ if (infos && infos.length > 0) {
213
+ infos.forEach((info) => {
214
+ const infoKeys = Object.keys(info);
215
+ /* istanbul ignore else */
216
+ if (infoKeys.indexOf("dependencies") > -1) {
217
+ info["dependencies"].forEach((d) => {
218
+ /* istanbul ignore else */
219
+ if (dependencies.indexOf(d) < 0) {
220
+ dependencies.push(d);
221
+ }
222
+ });
223
+ }
224
+ });
225
+ }
226
+ return dependencies.map(d => {
227
+ return { id: d, name: "" };
228
+ });
229
+ }
230
+ exports.getWorkforceDependencies = getWorkforceDependencies;
231
+ function getWorkforceServiceInfo(properties, url, authentication) {
232
+ return new Promise((resolve, reject) => {
233
+ url = url.replace("/rest/admin/services", "/rest/services");
234
+ url = _updateUrl(url);
235
+ const requests = [
236
+ (0, arcgis_rest_feature_layer_1.queryFeatures)({
237
+ url: `${url}3`,
238
+ where: "1=1",
239
+ authentication
240
+ }),
241
+ (0, arcgis_rest_feature_layer_1.queryFeatures)({
242
+ url: `${url}4`,
243
+ where: "1=1",
244
+ authentication
245
+ })
246
+ ];
247
+ Promise.all(requests).then(responses => {
248
+ const [assignmentTypes, assignmentIntegrations] = responses;
249
+ properties.workforceInfos = {
250
+ assignmentTypeInfos: _getAssignmentTypeInfos(assignmentTypes)
251
+ };
252
+ _getAssignmentIntegrationInfos(assignmentIntegrations, authentication).then(results => {
253
+ properties.workforceInfos["assignmentIntegrationInfos"] = results;
254
+ _updateGlobalIdAndAssignmentType(properties.workforceInfos);
255
+ resolve(properties);
256
+ }, e => reject((0, generalHelpers_1.fail)(e)));
257
+ }, e => reject((0, generalHelpers_1.fail)(e)));
258
+ });
259
+ }
260
+ exports.getWorkforceServiceInfo = getWorkforceServiceInfo;
261
+ /**
262
+ * Wrap global id and assignmenttype values in curly braces
263
+ *
264
+ * Added for issue #734
265
+ *
266
+ * This function will update the provided workforceInfos object
267
+ *
268
+ * @param workforceInfos the object that stores the integration and type info with global ids
269
+ * @private
270
+ */
271
+ function _updateGlobalIdAndAssignmentType(workforceInfos) {
272
+ const updateId = (i) => {
273
+ /* istanbul ignore else */
274
+ if (i["GlobalID"]) {
275
+ i["GlobalID"] = `{${i["GlobalID"]}}`;
276
+ }
277
+ /* istanbul ignore else */
278
+ if (i["assignmenttype"]) {
279
+ i["assignmenttype"] = `{${i["assignmenttype"]}}`;
280
+ }
281
+ return i;
282
+ };
283
+ const assignmentIntegrationInfos = (0, generalHelpers_1.getProp)(workforceInfos, "assignmentIntegrationInfos");
284
+ /* istanbul ignore else */
285
+ if (assignmentIntegrationInfos && Array.isArray(assignmentIntegrationInfos)) {
286
+ (0, generalHelpers_1.setProp)(workforceInfos, "assignmentIntegrationInfos", assignmentIntegrationInfos.map(updateId));
287
+ }
288
+ const assignmentTypeInfos = (0, generalHelpers_1.getProp)(workforceInfos, "assignmentTypeInfos");
289
+ /* istanbul ignore else */
290
+ if (assignmentTypeInfos && Array.isArray(assignmentTypeInfos)) {
291
+ (0, generalHelpers_1.setProp)(workforceInfos, "assignmentTypeInfos", assignmentTypeInfos.map(updateId));
292
+ }
293
+ }
294
+ exports._updateGlobalIdAndAssignmentType = _updateGlobalIdAndAssignmentType;
295
+ //TODO: function doc
296
+ function _getAssignmentTypeInfos(assignmentTypes) {
297
+ // Assignment Types
298
+ const assignmentTypeInfos = [];
299
+ const keyAssignmentTypeProps = [
300
+ "description",
301
+ assignmentTypes.globalIdFieldName
302
+ ];
303
+ assignmentTypes.features.forEach((f) => {
304
+ const info = {};
305
+ keyAssignmentTypeProps.forEach(p => {
306
+ info[p] = f.attributes[p];
307
+ });
308
+ assignmentTypeInfos.push(info);
309
+ });
310
+ return assignmentTypeInfos;
311
+ }
312
+ exports._getAssignmentTypeInfos = _getAssignmentTypeInfos;
313
+ //TODO: function doc
314
+ function _getAssignmentIntegrationInfos(assignmentIntegrations, authentication) {
315
+ return new Promise((resolve, reject) => {
316
+ let requests = [];
317
+ let urls = [];
318
+ const assignmentIntegrationInfos = [];
319
+ const keyAssignmentIntegrationsProps = [
320
+ "appid",
321
+ assignmentIntegrations.globalIdFieldName,
322
+ "prompt",
323
+ "urltemplate",
324
+ "assignmenttype"
325
+ ];
326
+ assignmentIntegrations.features.forEach((f) => {
327
+ const info = {};
328
+ keyAssignmentIntegrationsProps.forEach(p => {
329
+ info[p] = f.attributes[p];
330
+ /* istanbul ignore else */
331
+ if (p === "urltemplate") {
332
+ const urlTemplate = f.attributes[p];
333
+ const ids = (0, generalHelpers_1.getIDs)(urlTemplate);
334
+ info["dependencies"] = ids;
335
+ const serviceRequests = urlTest(urlTemplate, authentication);
336
+ /* istanbul ignore else */
337
+ if (Array.isArray(serviceRequests.requests) &&
338
+ serviceRequests.requests.length > 0) {
339
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
340
+ requests = requests.concat(serviceRequests.requests);
341
+ urls = urls.concat(serviceRequests.urls);
342
+ }
343
+ }
344
+ });
345
+ assignmentIntegrationInfos.push(info);
346
+ });
347
+ getUrlDependencies(requests, urls).then(results => {
348
+ assignmentIntegrationInfos.forEach(ai => {
349
+ _templatizeUrlTemplate(ai, results.urlHash);
350
+ });
351
+ resolve(assignmentIntegrationInfos);
352
+ }, e => reject((0, generalHelpers_1.fail)(e)));
353
+ });
354
+ }
355
+ exports._getAssignmentIntegrationInfos = _getAssignmentIntegrationInfos;
356
+ function getUrlDependencies(requests, urls) {
357
+ return new Promise((resolve, reject) => {
358
+ const dependencies = [];
359
+ if (requests.length > 0) {
360
+ Promise.all(requests).then(results => {
361
+ const urlHash = {};
362
+ // Get the serviceItemId for the url
363
+ /* istanbul ignore else */
364
+ if (Array.isArray(results)) {
365
+ results.forEach((result, i) => {
366
+ /* istanbul ignore else */
367
+ if (result.serviceItemId) {
368
+ urlHash[urls[i]] = result.serviceItemId;
369
+ /* istanbul ignore else */
370
+ if (dependencies.indexOf(result.serviceItemId) === -1) {
371
+ dependencies.push(result.serviceItemId);
372
+ }
373
+ }
374
+ });
375
+ }
376
+ resolve({
377
+ dependencies,
378
+ urlHash
379
+ });
380
+ }, e => reject((0, generalHelpers_1.fail)(e)));
381
+ }
382
+ else {
383
+ resolve({
384
+ dependencies,
385
+ urlHash: {}
386
+ });
387
+ }
388
+ });
389
+ }
390
+ exports.getUrlDependencies = getUrlDependencies;
391
+ /**
392
+ * Templatizes values from a urlTemplate
393
+ *
394
+ * @param item the object that may contain a urlTemplate
395
+ * @param urlHash a key value pair of url and itemId
396
+ * @private
397
+ */
398
+ function _templatizeUrlTemplate(item, urlHash) {
399
+ // v1 uses urlTemplate
400
+ // v2 uses urltemplate
401
+ const urlTemplateVar = (0, generalHelpers_1.getProp)(item, "urlTemplate")
402
+ ? "urlTemplate"
403
+ : "urltemplate";
404
+ let urlTemplate = (0, generalHelpers_1.getProp)(item, urlTemplateVar);
405
+ /* istanbul ignore else */
406
+ if (urlTemplate) {
407
+ const ids = (0, generalHelpers_1.getIDs)(urlTemplate);
408
+ ids.forEach(id => {
409
+ urlTemplate = urlTemplate.replace(id, (0, templatization_1.templatizeTerm)(id, id, ".itemId"));
410
+ });
411
+ const urls = _getURLs(urlTemplate);
412
+ urls.forEach(url => {
413
+ const layerId = getLayerId(url);
414
+ const replaceValue = getReplaceValue(layerId, ".url");
415
+ const id = urlHash[url];
416
+ /* istanbul ignore else */
417
+ if (Array.isArray(item.dependencies) &&
418
+ item.dependencies.indexOf(id) < 0) {
419
+ item.dependencies.push(id);
420
+ }
421
+ urlTemplate = urlTemplate.replace(url, (0, templatization_1.templatizeTerm)(id, id, replaceValue));
422
+ });
423
+ (0, generalHelpers_1.setProp)(item, urlTemplateVar, urlTemplate);
424
+ }
425
+ }
426
+ exports._templatizeUrlTemplate = _templatizeUrlTemplate;
427
+ function getLayerId(url) {
428
+ return url.indexOf("FeatureServer/") > -1
429
+ ? url.substr(url.lastIndexOf("/") + 1)
430
+ : undefined;
431
+ }
432
+ exports.getLayerId = getLayerId;
433
+ function getReplaceValue(layerId, suffix) {
434
+ return isNaN(Number.parseInt(layerId, 10))
435
+ ? `${suffix}`
436
+ : `.layer${layerId}${suffix}`;
437
+ }
438
+ exports.getReplaceValue = getReplaceValue;
439
+ function postProcessWorkforceTemplates(templates) {
440
+ const groupUpdates = {};
441
+ const _templates = templates.map(t => {
442
+ // templatize Workforce Project
443
+ t = _templatizeWorkforceProject(t, groupUpdates);
444
+ // templatize Workforce Dispatcher
445
+ t = _templatizeWorkforceDispatcherOrWorker(t, "Workforce Dispatcher");
446
+ // templatize Workforce Worker
447
+ t = _templatizeWorkforceDispatcherOrWorker(t, "Workforce Worker");
448
+ return t;
449
+ });
450
+ return _templates.map(t => {
451
+ if (groupUpdates[t.itemId]) {
452
+ t.dependencies = t.dependencies.concat(groupUpdates[t.itemId]);
453
+ }
454
+ return t;
455
+ });
456
+ }
457
+ exports.postProcessWorkforceTemplates = postProcessWorkforceTemplates;
458
+ //TODO: function doc
459
+ function _templatizeWorkforceProject(t, groupUpdates) {
460
+ /* istanbul ignore else */
461
+ if (isWorkforceProject(t)) {
462
+ const properties = t.item.properties || {};
463
+ const keyProperties = getKeyWorkforceProperties(2);
464
+ const groupId = properties["workforceProjectGroupId"];
465
+ const shuffleIds = [];
466
+ Object.keys(properties).forEach((p) => {
467
+ /* istanbul ignore else */
468
+ if (keyProperties.indexOf(p) > -1) {
469
+ const id = properties[p];
470
+ /* istanbul ignore else */
471
+ if (id !== groupId) {
472
+ shuffleIds.push(id);
473
+ }
474
+ t.item.properties[p] = (0, templatization_1.templatizeTerm)(properties[p], properties[p], ".itemId");
475
+ }
476
+ });
477
+ // update the dependencies
478
+ t.dependencies = t.dependencies.filter((d) => d !== groupId && shuffleIds.indexOf(d) < 0);
479
+ // shuffle and cleanup
480
+ const workforceInfos = (0, generalHelpers_1.getProp)(t, "properties.workforceInfos");
481
+ /* istanbul ignore else */
482
+ if (workforceInfos) {
483
+ Object.keys(workforceInfos).forEach(k => {
484
+ workforceInfos[k].forEach((wInfo) => {
485
+ /* istanbul ignore else */
486
+ if (wInfo.dependencies) {
487
+ wInfo.dependencies.forEach((id) => {
488
+ /* istanbul ignore else */
489
+ if (shuffleIds.indexOf(id) < 0) {
490
+ shuffleIds.push(id);
491
+ }
492
+ const depIndex = t.dependencies.indexOf(id);
493
+ /* istanbul ignore else */
494
+ if (depIndex > -1) {
495
+ t.dependencies.splice(depIndex, 1);
496
+ }
497
+ });
498
+ delete wInfo.dependencies;
499
+ }
500
+ });
501
+ });
502
+ }
503
+ // move the dependencies to the group
504
+ groupUpdates[groupId] = shuffleIds;
505
+ }
506
+ return t;
507
+ }
508
+ exports._templatizeWorkforceProject = _templatizeWorkforceProject;
509
+ //TODO: function doc
510
+ function _templatizeWorkforceDispatcherOrWorker(t, type) {
511
+ /* istanbul ignore else */
512
+ if ((t.item.typeKeywords || []).indexOf(type) > -1) {
513
+ const properties = t.item.properties || {};
514
+ const fsId = properties["workforceFeatureServiceId"];
515
+ /* istanbul ignore else */
516
+ if (fsId) {
517
+ t.item.properties["workforceFeatureServiceId"] = (0, templatization_1.templatizeTerm)(fsId, fsId, ".itemId");
518
+ }
519
+ }
520
+ return t;
521
+ }
522
+ exports._templatizeWorkforceDispatcherOrWorker = _templatizeWorkforceDispatcherOrWorker;
523
+ // Helpers
524
+ function isWorkforceProject(itemTemplate) {
525
+ return ((itemTemplate.item.typeKeywords || []).indexOf("Workforce Project") > -1);
526
+ }
527
+ exports.isWorkforceProject = isWorkforceProject;
528
+ function getKeyWorkforceProperties(version) {
529
+ return version === 1
530
+ ? [
531
+ "groupId",
532
+ "workerWebMapId",
533
+ "dispatcherWebMapId",
534
+ "dispatchers",
535
+ "assignments",
536
+ "workers",
537
+ "tracks"
538
+ ]
539
+ : [
540
+ "workforceDispatcherMapId",
541
+ "workforceProjectGroupId",
542
+ "workforceWorkerMapId"
543
+ ];
544
+ }
545
+ exports.getKeyWorkforceProperties = getKeyWorkforceProperties;
546
+ /**
547
+ * Test the provided value for any urls and submit a request to obtain the service item id for the url
548
+ *
549
+ * @param v a string value to test for urls
550
+ * @param authentication credentials for the requests
551
+ * @returns an object with any pending requests and the urls that requests were made to
552
+ */
553
+ function urlTest(v, authentication) {
554
+ const urls = _getURLs(v);
555
+ const requests = [];
556
+ urls.forEach(url => {
557
+ const options = {
558
+ f: "json",
559
+ authentication: authentication
560
+ };
561
+ requests.push((0, restHelpers_1.rest_request)(url, options));
562
+ });
563
+ return {
564
+ requests: requests,
565
+ urls: urls
566
+ };
567
+ }
568
+ exports.urlTest = urlTest;
569
+ //TODO: function doc
570
+ function _getURLs(v) {
571
+ return (0, generalHelpers_1.regExTest)(v, /=(http.*?FeatureServer.*?(?=&|$))/gi).map(_v => _v.replace("=", ""));
572
+ }
573
+ exports._getURLs = _getURLs;
574
+ //#region Deploy Process ---------------------------------------------------------------------------------------//
575
+ /**
576
+ * Gets the current user and updates the dispatchers service
577
+ *
578
+ * @param newlyCreatedItem Item to be created; n.b.: this item is modified
579
+ * @param destinationAuthentication The session used to create the new item(s)
580
+ * @returns A promise that will resolve with \{ "success" === true || false \}
581
+ */
582
+ function fineTuneCreatedWorkforceItem(newlyCreatedItem, destinationAuthentication, url, templateDictionary) {
583
+ return new Promise((resolve, reject) => {
584
+ destinationAuthentication.getUser().then(user => {
585
+ // update url with slash if necessary
586
+ url = _updateUrl(url);
587
+ // Dispatchers...index 2 for workforce v2
588
+ // for v1 we need tp fetch from dispatchers for v2 we use the items url
589
+ const dispatchers = (0, generalHelpers_1.getProp)(newlyCreatedItem, "data.dispatchers");
590
+ // add current user as dispatcher
591
+ _updateDispatchers(dispatchers && dispatchers.url ? dispatchers.url : `${url}2`, user.username || "", user.fullName || "", destinationAuthentication, templateDictionary.isPortal).then(results => {
592
+ // for workforce v2 we storce the key details from the workforce service as workforceInfos
593
+ // now we need to detemplatize it and update the workforce service
594
+ let workforceInfos = (0, generalHelpers_1.getProp)(newlyCreatedItem, "properties.workforceInfos");
595
+ if (workforceInfos && url) {
596
+ workforceInfos = (0, templatization_1.replaceInTemplate)(workforceInfos, templateDictionary);
597
+ _getFields(url, [2, 3, 4], destinationAuthentication).then(fields => {
598
+ // Assignment Types...index 3
599
+ const assignmentTypeUrl = `${url}3`;
600
+ const assignmentTypeInfos = workforceInfos.assignmentTypeInfos;
601
+ const assignmentTypeFeatures = _getAddFeatures(assignmentTypeInfos, fields[assignmentTypeUrl]);
602
+ const assignmentTypePromise = _applyEdits(assignmentTypeUrl, assignmentTypeFeatures, destinationAuthentication, true);
603
+ // Assignment Integrations...index 4
604
+ const assignmentIntegrationUrl = `${url}4`;
605
+ const assignmentIntegrationInfos = workforceInfos.assignmentIntegrationInfos;
606
+ const assignmentIntegrationFeatures = _getAddFeatures(assignmentIntegrationInfos, fields[assignmentIntegrationUrl]);
607
+ const assignmentIntegrationPromise = _applyEdits(assignmentIntegrationUrl, assignmentIntegrationFeatures, destinationAuthentication, true);
608
+ Promise.all([
609
+ assignmentTypePromise,
610
+ assignmentIntegrationPromise
611
+ ]).then(resolve, reject);
612
+ }, e => reject((0, generalHelpers_1.fail)(e)));
613
+ }
614
+ else {
615
+ resolve({ success: results });
616
+ }
617
+ }, e => reject((0, generalHelpers_1.fail)(e)));
618
+ }, e => reject((0, generalHelpers_1.fail)(e)));
619
+ });
620
+ }
621
+ exports.fineTuneCreatedWorkforceItem = fineTuneCreatedWorkforceItem;
622
+ //TODO: function doc
623
+ function _getFields(url, ids, authentication) {
624
+ return new Promise((resolve, reject) => {
625
+ const options = {
626
+ f: "json",
627
+ fields: "*",
628
+ authentication: authentication
629
+ };
630
+ url = _updateUrl(url);
631
+ const promises = [];
632
+ ids.forEach(id => {
633
+ promises.push((0, restHelpers_1.rest_request)(`${url}${id}`, options));
634
+ });
635
+ Promise.all(promises).then(results => {
636
+ const finalResult = {};
637
+ results.forEach(r => {
638
+ finalResult[`${url}${r.id}`] = r.fields.map((f) => f.name);
639
+ });
640
+ resolve(finalResult);
641
+ }, e => reject((0, generalHelpers_1.fail)(e)));
642
+ });
643
+ }
644
+ exports._getFields = _getFields;
645
+ //TODO: function doc
646
+ function _updateUrl(url) {
647
+ url += url.endsWith("/") ? "" : "/";
648
+ return url;
649
+ }
650
+ exports._updateUrl = _updateUrl;
651
+ //TODO: function doc
652
+ function _getAddFeatures(updateInfos, fields) {
653
+ const features = [];
654
+ updateInfos.forEach((update) => {
655
+ const f = {};
656
+ Object.keys(update).forEach(k => {
657
+ const fieldName = _getField(k, fields);
658
+ f[fieldName] = update[k];
659
+ });
660
+ features.push({ attributes: f });
661
+ });
662
+ return features;
663
+ }
664
+ exports._getAddFeatures = _getAddFeatures;
665
+ //TODO: function doc
666
+ function _getField(name, fields) {
667
+ return fields.filter(f => f.toLowerCase() === name.toLowerCase())[0];
668
+ }
669
+ exports._getField = _getField;
670
+ /**
671
+ * Updates the dispatchers service to include the current user as a dispatcher
672
+ *
673
+ * @param dispatchers The dispatchers object from the workforce items data
674
+ * @param name Current users name
675
+ * @param fullName Current users full name
676
+ * @param destinationAuthentication The session used to create the new item(s)
677
+ * @returns A promise that will resolve with true || false
678
+ * @private
679
+ */
680
+ function _updateDispatchers(url, name, fullName, authentication, isPortal) {
681
+ return new Promise((resolve, reject) => {
682
+ if (url) {
683
+ const fieldName = isPortal ? "userid" : "userId";
684
+ (0, arcgis_rest_feature_layer_1.queryFeatures)({
685
+ url,
686
+ where: `${fieldName} = '${name}'`,
687
+ authentication
688
+ }).then((results) => {
689
+ if (results && results.features) {
690
+ if (results.features.length === 0) {
691
+ const features = [
692
+ {
693
+ attributes: {
694
+ name: fullName
695
+ }
696
+ }
697
+ ];
698
+ features[0].attributes[fieldName] = name;
699
+ _applyEdits(url, features, authentication).then(resolve, reject);
700
+ }
701
+ else {
702
+ resolve(true);
703
+ }
704
+ }
705
+ else {
706
+ resolve(false);
707
+ }
708
+ }, e => reject((0, generalHelpers_1.fail)(e)));
709
+ }
710
+ else {
711
+ resolve(false);
712
+ }
713
+ });
714
+ }
715
+ exports._updateDispatchers = _updateDispatchers;
716
+ //TODO: function doc
717
+ function _applyEdits(url, adds, authentication, useGlobalIds = false // only set when contains a globalid
718
+ ) {
719
+ return new Promise((resolve, reject) => {
720
+ if (adds.length > 0) {
721
+ (0, arcgis_rest_feature_layer_1.applyEdits)({
722
+ url,
723
+ adds,
724
+ useGlobalIds,
725
+ authentication
726
+ }).then(addResults => {
727
+ if (addResults && addResults.addResults) {
728
+ resolve(true);
729
+ }
730
+ else {
731
+ reject((0, generalHelpers_1.fail)({
732
+ success: false,
733
+ message: "Failed to add dispatch record."
734
+ }));
735
+ }
736
+ }, e => reject((0, generalHelpers_1.fail)({
737
+ success: false,
738
+ message: "Failed to add dispatch record.",
739
+ error: e
740
+ })));
741
+ }
742
+ else {
743
+ resolve(true);
744
+ }
745
+ });
746
+ }
747
+ exports._applyEdits = _applyEdits;
748
+ //#endregion
749
+ //# sourceMappingURL=workforceHelpers.js.map