@esri/solution-deployer 0.23.1 → 1.1.3

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 (42) hide show
  1. package/dist/esm/deploySolutionFromTemplate.js +77 -74
  2. package/dist/esm/deploySolutionFromTemplate.js.map +1 -1
  3. package/dist/esm/deploySolutionItems.d.ts +25 -1
  4. package/dist/esm/deploySolutionItems.js +239 -151
  5. package/dist/esm/deploySolutionItems.js.map +1 -1
  6. package/dist/esm/deployer.js +16 -17
  7. package/dist/esm/deployer.js.map +1 -1
  8. package/dist/esm/deployerUtils.js +17 -22
  9. package/dist/esm/deployerUtils.js.map +1 -1
  10. package/dist/esm/helpers/post-process.js +13 -18
  11. package/dist/esm/helpers/post-process.js.map +1 -1
  12. package/dist/esm/helpers/share-templates-to-groups.js +29 -6
  13. package/dist/esm/helpers/share-templates-to-groups.js.map +1 -1
  14. package/dist/esm/helpers/sortTemplates.js +2 -4
  15. package/dist/esm/helpers/sortTemplates.js.map +1 -1
  16. package/dist/esm/module-map.js +7 -6
  17. package/dist/esm/module-map.js.map +1 -1
  18. package/dist/node/deploySolutionFromTemplate.js +83 -80
  19. package/dist/node/deploySolutionFromTemplate.js.map +1 -1
  20. package/dist/node/deploySolutionItems.d.ts +25 -1
  21. package/dist/node/deploySolutionItems.js +244 -154
  22. package/dist/node/deploySolutionItems.js.map +1 -1
  23. package/dist/node/deployer.js +23 -24
  24. package/dist/node/deployer.js.map +1 -1
  25. package/dist/node/deployerUtils.js +18 -23
  26. package/dist/node/deployerUtils.js.map +1 -1
  27. package/dist/node/helpers/post-process.js +18 -23
  28. package/dist/node/helpers/post-process.js.map +1 -1
  29. package/dist/node/helpers/share-templates-to-groups.js +30 -7
  30. package/dist/node/helpers/share-templates-to-groups.js.map +1 -1
  31. package/dist/node/helpers/sortTemplates.js +2 -4
  32. package/dist/node/helpers/sortTemplates.js.map +1 -1
  33. package/dist/node/index.js +5 -5
  34. package/dist/node/index.js.map +1 -1
  35. package/dist/node/module-map.js +13 -12
  36. package/dist/node/module-map.js.map +1 -1
  37. package/dist/umd/deploySolutionItems.d.ts +25 -1
  38. package/dist/umd/deployer.umd.js +1622 -1550
  39. package/dist/umd/deployer.umd.js.map +1 -1
  40. package/dist/umd/deployer.umd.min.js +3 -3
  41. package/dist/umd/deployer.umd.min.js.map +1 -1
  42. package/package.json +31 -30
@@ -1,7 +1,7 @@
1
1
  /* @preserve
2
- * @esri/solution-deployer - v0.23.1 - Apache-2.0
2
+ * @esri/solution-deployer - v1.1.3 - Apache-2.0
3
3
  * Copyright (c) 2018-2021 Esri, Inc.
4
- * Fri Jun 04 2021 08:33:33 GMT-0700 (Pacific Daylight Time)
4
+ * Mon Oct 18 2021 09:05:22 GMT-0700 (Pacific Daylight Time)
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -16,1564 +16,1636 @@
16
16
  * limitations under the License.
17
17
  */
18
18
  (function (global, factory) {
19
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/solution-common'), require('@esri/solution-feature-layer'), require('@esri/solution-file'), require('@esri/solution-form'), require('@esri/solution-group'), require('@esri/solution-simple-types'), require('@esri/solution-storymap'), require('@esri/solution-web-experience'), require('@esri/solution-hub-types'), require('@esri/hub-common'), require('@esri/arcgis-rest-portal')) :
20
- typeof define === 'function' && define.amd ? define(['exports', '@esri/solution-common', '@esri/solution-feature-layer', '@esri/solution-file', '@esri/solution-form', '@esri/solution-group', '@esri/solution-simple-types', '@esri/solution-storymap', '@esri/solution-web-experience', '@esri/solution-hub-types', '@esri/hub-common', '@esri/arcgis-rest-portal'], factory) :
21
- (global = global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisHub, global.arcgisRest));
22
- }(this, (function (exports, common, featureLayer, fileProcessor, formProcessor, group, solutionSimpleTypes, solutionStorymap, solutionWebExperience, solutionHubTypes, hubCommon, arcgisRestPortal) { 'use strict';
19
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/solution-common'), require('@esri/solution-feature-layer'), require('@esri/solution-file'), require('@esri/solution-form'), require('@esri/solution-group'), require('@esri/solution-simple-types'), require('@esri/solution-storymap'), require('@esri/solution-velocity'), require('@esri/solution-web-experience'), require('@esri/solution-hub-types'), require('@esri/hub-common'), require('@esri/arcgis-rest-portal')) :
20
+ typeof define === 'function' && define.amd ? define(['exports', '@esri/solution-common', '@esri/solution-feature-layer', '@esri/solution-file', '@esri/solution-form', '@esri/solution-group', '@esri/solution-simple-types', '@esri/solution-storymap', '@esri/solution-velocity', '@esri/solution-web-experience', '@esri/solution-hub-types', '@esri/hub-common', '@esri/arcgis-rest-portal'], factory) :
21
+ (global = global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisHub, global.arcgisRest));
22
+ }(this, (function (exports, common, featureLayer, fileProcessor, formProcessor, group, solutionSimpleTypes, solutionStorymap, solutionVelocity, solutionWebExperience, solutionHubTypes, hubCommon, portal) { 'use strict';
23
23
 
24
- /*! *****************************************************************************
25
- Copyright (c) Microsoft Corporation. All rights reserved.
26
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
27
- this file except in compliance with the License. You may obtain a copy of the
28
- License at http://www.apache.org/licenses/LICENSE-2.0
29
-
30
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
31
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
32
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
33
- MERCHANTABLITY OR NON-INFRINGEMENT.
34
-
35
- See the Apache Version 2.0 License for specific language governing permissions
36
- and limitations under the License.
37
- ***************************************************************************** */
38
-
39
- var __assign = function() {
40
- __assign = Object.assign || function __assign(t) {
41
- for (var s, i = 1, n = arguments.length; i < n; i++) {
42
- s = arguments[i];
43
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
44
- }
45
- return t;
46
- };
47
- return __assign.apply(this, arguments);
48
- };
49
-
50
- function __read(o, n) {
51
- var m = typeof Symbol === "function" && o[Symbol.iterator];
52
- if (!m) return o;
53
- var i = m.call(o), r, ar = [], e;
54
- try {
55
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
56
- }
57
- catch (error) { e = { error: error }; }
58
- finally {
59
- try {
60
- if (r && !r.done && (m = i["return"])) m.call(i);
61
- }
62
- finally { if (e) throw e.error; }
63
- }
64
- return ar;
65
- }
66
-
67
- function __spread() {
68
- for (var ar = [], i = 0; i < arguments.length; i++)
69
- ar = ar.concat(__read(arguments[i]));
70
- return ar;
71
- }
24
+ /** @license
25
+ * Copyright 2020 Esri
26
+ *
27
+ * Licensed under the Apache License, Version 2.0 (the "License");
28
+ * you may not use this file except in compliance with the License.
29
+ * You may obtain a copy of the License at
30
+ *
31
+ * http://www.apache.org/licenses/LICENSE-2.0
32
+ *
33
+ * Unless required by applicable law or agreed to in writing, software
34
+ * distributed under the License is distributed on an "AS IS" BASIS,
35
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36
+ * See the License for the specific language governing permissions and
37
+ * limitations under the License.
38
+ */
39
+ const UNSUPPORTED = null;
40
+ /**
41
+ * Mapping from item type to module with type-specific template-handling code.
42
+ * AGO types come from a blend of arcgis-portal-app\src\js\arcgisonline\pages\item\_Info.js and
43
+ * arcgis-portal-app\src\js\arcgis-components\src\_utils\metadata\item\displayName.ts
44
+ */
45
+ const moduleMap = {
46
+ ////////////////////////////////////////////////////////
47
+ // Group type
48
+ Group: group,
49
+ ////////////////////////////////////////////////////////
50
+ // Layer types
51
+ "Big Data Analytic": solutionVelocity.VelocityProcessor,
52
+ "Feature Collection": solutionSimpleTypes.simpleTypes,
53
+ "Feature Service": featureLayer,
54
+ Feed: solutionVelocity.VelocityProcessor,
55
+ "Geocoding Service": undefined,
56
+ "Geodata Service": undefined,
57
+ "Geometry Service": undefined,
58
+ "Geoprocessing Service": undefined,
59
+ "Globe Service": undefined,
60
+ "Image Service": undefined,
61
+ KML: undefined,
62
+ "Map Service": featureLayer,
63
+ "Network Analysis Service": undefined,
64
+ "Real Time Analytic": solutionVelocity.VelocityProcessor,
65
+ "Relational Database Connection": undefined,
66
+ "Scene Service": undefined,
67
+ "Stream Service": undefined,
68
+ Tool: undefined,
69
+ "Vector Tile Service": undefined,
70
+ WFS: undefined,
71
+ WMS: undefined,
72
+ WMTS: undefined,
73
+ "Workflow Manager Service": undefined,
74
+ ////////////////////////////////////////////////////////
75
+ // Map types
76
+ "3D Web Scene": undefined,
77
+ "Web Map": solutionSimpleTypes.simpleTypes,
78
+ "Web Scene": solutionSimpleTypes.simpleTypes,
79
+ ////////////////////////////////////////////////////////
80
+ // App types
81
+ Application: undefined,
82
+ Dashboard: solutionSimpleTypes.simpleTypes,
83
+ "Data Store": undefined,
84
+ "Desktop Application": undefined,
85
+ "Excalibur Imagery Project": undefined,
86
+ Form: formProcessor,
87
+ "Hub Initiative": UNSUPPORTED,
88
+ "Hub Page": solutionHubTypes.HubPageProcessor,
89
+ "Hub Site Application": solutionHubTypes.HubSiteProcessor,
90
+ "Insights Model": solutionSimpleTypes.simpleTypes,
91
+ "Insights Page": undefined,
92
+ "Insights Theme": undefined,
93
+ "Insights Workbook": undefined,
94
+ Mission: undefined,
95
+ "Mobile Application": undefined,
96
+ Notebook: solutionSimpleTypes.notebookProcessor,
97
+ "Oriented Imagery Catalog": solutionSimpleTypes.simpleTypes,
98
+ "Ortho Mapping Project": undefined,
99
+ "QuickCapture Project": solutionSimpleTypes.quickcaptureProcessor,
100
+ "Site Application": solutionHubTypes.HubSiteProcessor,
101
+ "Site Page": solutionHubTypes.HubPageProcessor,
102
+ Solution: UNSUPPORTED,
103
+ StoryMap: solutionStorymap.StoryMapProcessor,
104
+ "Urban Model": undefined,
105
+ "Web Experience Template": undefined,
106
+ "Web Experience": solutionWebExperience.WebExperienceProcessor,
107
+ "Web Mapping Application": solutionSimpleTypes.simpleTypes,
108
+ "Workforce Project": solutionSimpleTypes.simpleTypes,
109
+ ////////////////////////////////////////////////////////
110
+ // File types
111
+ "360 VR Experience": fileProcessor,
112
+ "AppBuilder Extension": fileProcessor,
113
+ "AppBuilder Widget Package": fileProcessor,
114
+ "Application Configuration": fileProcessor,
115
+ "ArcGIS Pro Add In": fileProcessor,
116
+ "ArcGIS Pro Configuration": fileProcessor,
117
+ "ArcPad Package": fileProcessor,
118
+ "Basemap Package": fileProcessor,
119
+ "CAD Drawing": fileProcessor,
120
+ "CityEngine Web Scene": fileProcessor,
121
+ "Code Attachment": UNSUPPORTED,
122
+ "Code Sample": fileProcessor,
123
+ "Color Set": fileProcessor,
124
+ "Compact Tile Package": fileProcessor,
125
+ "CSV Collection": fileProcessor,
126
+ CSV: fileProcessor,
127
+ "Deep Learning Package": fileProcessor,
128
+ "Desktop Add In": fileProcessor,
129
+ "Desktop Application Template": fileProcessor,
130
+ "Desktop Style": fileProcessor,
131
+ "Document Link": fileProcessor,
132
+ "Explorer Add In": fileProcessor,
133
+ "Explorer Layer": fileProcessor,
134
+ "Explorer Map": fileProcessor,
135
+ "Feature Collection Template": fileProcessor,
136
+ "File Geodatabase": fileProcessor,
137
+ GeoJson: fileProcessor,
138
+ GeoPackage: fileProcessor,
139
+ "Geoprocessing Package": fileProcessor,
140
+ "Geoprocessing Sample": fileProcessor,
141
+ "Globe Document": fileProcessor,
142
+ "Image Collection": fileProcessor,
143
+ Image: fileProcessor,
144
+ "iWork Keynote": fileProcessor,
145
+ "iWork Numbers": fileProcessor,
146
+ "iWork Pages": fileProcessor,
147
+ "KML Collection": fileProcessor,
148
+ "Layer Package": fileProcessor,
149
+ "Layer Template": fileProcessor,
150
+ Layer: fileProcessor,
151
+ Layout: fileProcessor,
152
+ "Locator Package": fileProcessor,
153
+ "Map Document": fileProcessor,
154
+ "Map Package": fileProcessor,
155
+ "Map Template": fileProcessor,
156
+ "Microsoft Excel": fileProcessor,
157
+ "Microsoft Powerpoint": fileProcessor,
158
+ "Microsoft Word": fileProcessor,
159
+ "Mobile Basemap Package": fileProcessor,
160
+ "Mobile Map Package": fileProcessor,
161
+ "Mobile Scene Package": fileProcessor,
162
+ "Native Application": fileProcessor,
163
+ "Native Application Installer": fileProcessor,
164
+ "Native Application Template": fileProcessor,
165
+ netCDF: fileProcessor,
166
+ "Operation View": fileProcessor,
167
+ "Operations Dashboard Add In": fileProcessor,
168
+ "Operations Dashboard Extension": fileProcessor,
169
+ PDF: fileProcessor,
170
+ "Pro Layer Package": fileProcessor,
171
+ "Pro Layer": fileProcessor,
172
+ "Pro Map Package": fileProcessor,
173
+ "Pro Map": fileProcessor,
174
+ "Pro Report": fileProcessor,
175
+ "Project Package": fileProcessor,
176
+ "Project Template": fileProcessor,
177
+ "Published Map": fileProcessor,
178
+ "Raster function template": fileProcessor,
179
+ "Report Template": fileProcessor,
180
+ "Rule Package": fileProcessor,
181
+ "Scene Document": fileProcessor,
182
+ "Scene Package": fileProcessor,
183
+ "Service Definition": fileProcessor,
184
+ Shapefile: fileProcessor,
185
+ "Statistical Data Collection": fileProcessor,
186
+ Style: fileProcessor,
187
+ "Survey123 Add In": fileProcessor,
188
+ "Symbol Set": fileProcessor,
189
+ "Task File": fileProcessor,
190
+ "Tile Package": fileProcessor,
191
+ "Toolbox Package": fileProcessor,
192
+ "Vector Tile Package": fileProcessor,
193
+ "Viewer Configuration": fileProcessor,
194
+ "Visio Document": fileProcessor,
195
+ "Window Mobile Package": fileProcessor,
196
+ "Windows Mobile Package": fileProcessor,
197
+ "Windows Viewer Add In": fileProcessor,
198
+ "Windows Viewer Configuration": fileProcessor,
199
+ "Workflow Manager Package": fileProcessor,
200
+ ////////////////////////////////////////////////////////
201
+ // Testing "types"
202
+ Undefined: undefined,
203
+ Unsupported: UNSUPPORTED
204
+ };
72
205
 
73
- /** @license
74
- * Copyright 2020 Esri
75
- *
76
- * Licensed under the Apache License, Version 2.0 (the "License");
77
- * you may not use this file except in compliance with the License.
78
- * You may obtain a copy of the License at
79
- *
80
- * http://www.apache.org/licenses/LICENSE-2.0
81
- *
82
- * Unless required by applicable law or agreed to in writing, software
83
- * distributed under the License is distributed on an "AS IS" BASIS,
84
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
85
- * See the License for the specific language governing permissions and
86
- * limitations under the License.
87
- */
88
- var UNSUPPORTED = null;
89
- /**
90
- * Mapping from item type to module with type-specific template-handling code.
91
- * AGO types come from a blend of arcgis-portal-app\src\js\arcgisonline\pages\item\_Info.js and
92
- * arcgis-portal-app\src\js\arcgis-components\src\_utils\metadata\item\displayName.ts
93
- */
94
- var moduleMap = {
95
- ////////////////////////////////////////////////////////
96
- // Group type
97
- Group: group,
98
- ////////////////////////////////////////////////////////
99
- // Layer types
100
- "Big Data Analytic": undefined,
101
- "Feature Collection": solutionSimpleTypes.simpleTypes,
102
- "Feature Service": featureLayer,
103
- Feed: undefined,
104
- "Geocoding Service": undefined,
105
- "Geodata Service": undefined,
106
- "Geometry Service": undefined,
107
- "Geoprocessing Service": undefined,
108
- "Globe Service": undefined,
109
- "Image Service": undefined,
110
- KML: undefined,
111
- "Map Service": featureLayer,
112
- "Network Analysis Service": undefined,
113
- "Real Time Analytic": undefined,
114
- "Relational Database Connection": undefined,
115
- "Scene Service": undefined,
116
- "Stream Service": undefined,
117
- Tool: undefined,
118
- "Vector Tile Service": undefined,
119
- WFS: undefined,
120
- WMS: undefined,
121
- WMTS: undefined,
122
- "Workflow Manager Service": undefined,
123
- ////////////////////////////////////////////////////////
124
- // Map types
125
- "3D Web Scene": undefined,
126
- "Web Map": solutionSimpleTypes.simpleTypes,
127
- "Web Scene": undefined,
128
- ////////////////////////////////////////////////////////
129
- // App types
130
- Application: undefined,
131
- Dashboard: solutionSimpleTypes.simpleTypes,
132
- "Data Store": undefined,
133
- "Desktop Application": undefined,
134
- "Excalibur Imagery Project": undefined,
135
- Form: formProcessor,
136
- "Hub Initiative": UNSUPPORTED,
137
- "Hub Page": solutionHubTypes.HubPageProcessor,
138
- "Hub Site Application": solutionHubTypes.HubSiteProcessor,
139
- "Insights Model": solutionSimpleTypes.simpleTypes,
140
- "Insights Page": undefined,
141
- "Insights Theme": undefined,
142
- "Insights Workbook": undefined,
143
- Mission: undefined,
144
- "Mobile Application": undefined,
145
- Notebook: solutionSimpleTypes.notebookProcessor,
146
- "Oriented Imagery Catalog": solutionSimpleTypes.simpleTypes,
147
- "Ortho Mapping Project": undefined,
148
- "QuickCapture Project": solutionSimpleTypes.quickcaptureProcessor,
149
- "Site Application": solutionHubTypes.HubSiteProcessor,
150
- "Site Page": solutionHubTypes.HubPageProcessor,
151
- Solution: UNSUPPORTED,
152
- StoryMap: solutionStorymap.StoryMapProcessor,
153
- "Urban Model": undefined,
154
- "Web Experience Template": undefined,
155
- "Web Experience": solutionWebExperience.WebExperienceProcessor,
156
- "Web Mapping Application": solutionSimpleTypes.simpleTypes,
157
- "Workforce Project": solutionSimpleTypes.simpleTypes,
158
- ////////////////////////////////////////////////////////
159
- // File types
160
- "360 VR Experience": fileProcessor,
161
- "AppBuilder Extension": fileProcessor,
162
- "AppBuilder Widget Package": fileProcessor,
163
- "Application Configuration": fileProcessor,
164
- "ArcGIS Pro Add In": fileProcessor,
165
- "ArcGIS Pro Configuration": fileProcessor,
166
- "ArcPad Package": fileProcessor,
167
- "Basemap Package": fileProcessor,
168
- "CAD Drawing": fileProcessor,
169
- "CityEngine Web Scene": fileProcessor,
170
- "Code Attachment": UNSUPPORTED,
171
- "Code Sample": fileProcessor,
172
- "Color Set": fileProcessor,
173
- "Compact Tile Package": fileProcessor,
174
- "CSV Collection": fileProcessor,
175
- CSV: fileProcessor,
176
- "Deep Learning Package": fileProcessor,
177
- "Desktop Add In": fileProcessor,
178
- "Desktop Application Template": fileProcessor,
179
- "Desktop Style": fileProcessor,
180
- "Document Link": fileProcessor,
181
- "Explorer Add In": fileProcessor,
182
- "Explorer Layer": fileProcessor,
183
- "Explorer Map": fileProcessor,
184
- "Feature Collection Template": fileProcessor,
185
- "File Geodatabase": fileProcessor,
186
- GeoJson: fileProcessor,
187
- GeoPackage: fileProcessor,
188
- "Geoprocessing Package": fileProcessor,
189
- "Geoprocessing Sample": fileProcessor,
190
- "Globe Document": fileProcessor,
191
- "Image Collection": fileProcessor,
192
- Image: fileProcessor,
193
- "iWork Keynote": fileProcessor,
194
- "iWork Numbers": fileProcessor,
195
- "iWork Pages": fileProcessor,
196
- "KML Collection": fileProcessor,
197
- "Layer Package": fileProcessor,
198
- "Layer Template": fileProcessor,
199
- Layer: fileProcessor,
200
- Layout: fileProcessor,
201
- "Locator Package": fileProcessor,
202
- "Map Document": fileProcessor,
203
- "Map Package": fileProcessor,
204
- "Map Template": fileProcessor,
205
- "Microsoft Excel": fileProcessor,
206
- "Microsoft Powerpoint": fileProcessor,
207
- "Microsoft Word": fileProcessor,
208
- "Mobile Basemap Package": fileProcessor,
209
- "Mobile Map Package": fileProcessor,
210
- "Mobile Scene Package": fileProcessor,
211
- "Native Application": fileProcessor,
212
- "Native Application Installer": fileProcessor,
213
- "Native Application Template": fileProcessor,
214
- netCDF: fileProcessor,
215
- "Operation View": fileProcessor,
216
- "Operations Dashboard Add In": fileProcessor,
217
- "Operations Dashboard Extension": fileProcessor,
218
- PDF: fileProcessor,
219
- "Pro Layer Package": fileProcessor,
220
- "Pro Layer": fileProcessor,
221
- "Pro Map Package": fileProcessor,
222
- "Pro Map": fileProcessor,
223
- "Pro Report": fileProcessor,
224
- "Project Package": fileProcessor,
225
- "Project Template": fileProcessor,
226
- "Published Map": fileProcessor,
227
- "Raster function template": fileProcessor,
228
- "Report Template": fileProcessor,
229
- "Rule Package": fileProcessor,
230
- "Scene Document": fileProcessor,
231
- "Scene Package": fileProcessor,
232
- "Service Definition": fileProcessor,
233
- Shapefile: fileProcessor,
234
- "Statistical Data Collection": fileProcessor,
235
- Style: fileProcessor,
236
- "Survey123 Add In": fileProcessor,
237
- "Symbol Set": fileProcessor,
238
- "Task File": fileProcessor,
239
- "Tile Package": fileProcessor,
240
- "Toolbox Package": fileProcessor,
241
- "Vector Tile Package": fileProcessor,
242
- "Viewer Configuration": fileProcessor,
243
- "Visio Document": fileProcessor,
244
- "Window Mobile Package": fileProcessor,
245
- "Windows Mobile Package": fileProcessor,
246
- "Windows Viewer Add In": fileProcessor,
247
- "Windows Viewer Configuration": fileProcessor,
248
- "Workflow Manager Package": fileProcessor,
249
- ////////////////////////////////////////////////////////
250
- // Testing "types"
251
- Undefined: undefined,
252
- Unsupported: UNSUPPORTED
253
- };
206
+ /** @license
207
+ * Copyright 2018 Esri
208
+ *
209
+ * Licensed under the Apache License, Version 2.0 (the "License");
210
+ * you may not use this file except in compliance with the License.
211
+ * You may obtain a copy of the License at
212
+ *
213
+ * http://www.apache.org/licenses/LICENSE-2.0
214
+ *
215
+ * Unless required by applicable law or agreed to in writing, software
216
+ * distributed under the License is distributed on an "AS IS" BASIS,
217
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
218
+ * See the License for the specific language governing permissions and
219
+ * limitations under the License.
220
+ */
221
+ const UNSUPPORTED$1 = null;
222
+ // ------------------------------------------------------------------------------------------------------------------ //
223
+ /**
224
+ * Deploys a set of items defined by templates.
225
+ *
226
+ * @param portalSharingUrl Server/sharing
227
+ * @param storageItemId Id of storage item
228
+ * @param templates A collection of AGO item templates
229
+ * @param storageAuthentication Credentials for the organization with the source items
230
+ * @param templateDictionary Hash of facts: org URL, adlib replacements
231
+ * @param deployedSolutionId Id of deployed Solution item
232
+ * @param destinationAuthentication Credentials for the destination organization
233
+ * @param options Options to tune deployment
234
+ * @return A promise that will resolve with the list of information about the created items
235
+ */
236
+ function deploySolutionItems(portalSharingUrl, storageItemId, templates, storageAuthentication, templateDictionary, deployedSolutionId, destinationAuthentication, options) {
237
+ return new Promise((resolve, reject) => {
238
+ // Prepare feedback mechanism
239
+ const totalEstimatedCost = _estimateDeploymentCost(templates) + 1; // solution items, plus avoid divide by 0
240
+ let percentDone = 10; // allow for previous deployment work
241
+ const progressPercentStep = (99 - percentDone) / totalEstimatedCost; // leave some % for caller for wrapup
242
+ const failedTemplateItemIds = [];
243
+ const deployedItemIds = [];
244
+ let statusOK = true;
245
+ // TODO: move to separate fn
246
+ const itemProgressCallback = (itemId, status, costUsed, createdItemId // supplied when status is EItemProgressStatus.Created or .Finished
247
+ ) => {
248
+ percentDone += progressPercentStep * costUsed;
249
+ /* istanbul ignore else */
250
+ if (options.progressCallback) {
251
+ if (status === common.EItemProgressStatus.Finished) {
252
+ const event = {
253
+ event: common.SItemProgressStatus[status],
254
+ data: itemId
255
+ };
256
+ options.progressCallback(Math.round(percentDone), options.jobId, event);
257
+ }
258
+ else {
259
+ options.progressCallback(Math.round(percentDone), options.jobId);
260
+ }
261
+ }
262
+ /* istanbul ignore if */
263
+ if (options.consoleProgress) {
264
+ console.log(Date.now(), itemId, options.jobId ?? "", common.SItemProgressStatus[status], percentDone.toFixed(0) + "%", costUsed, createdItemId ? "==> " + createdItemId : "");
265
+ }
266
+ if (status === common.EItemProgressStatus.Created) {
267
+ deployedItemIds.push(createdItemId);
268
+ }
269
+ else if (status === common.EItemProgressStatus.Failed) {
270
+ failedTemplateItemIds.push(itemId);
271
+ console.error("Item " + itemId + " has failed");
272
+ statusOK = false;
273
+ }
274
+ return statusOK;
275
+ // ---------------------------------------------------------------------------------------------------------------
276
+ };
277
+ // portal does not allow views of a single source to be created at the same time
278
+ if (common.getProp(templateDictionary, "organization.isPortal")) {
279
+ templates = _evaluateSharedViewSources(templates);
280
+ }
281
+ // Create an ordered graph of the templates so that dependencies are created before the items that need them.
282
+ // Because cycles are permitted, we also keep track of items that need to be patched later because their
283
+ // dependencies are necessarily created after they are created.
284
+ const { buildOrder, itemsToBePatched } = common.topologicallySortItems(templates);
285
+ // For each item in order from no dependencies to dependent on other items,
286
+ // * replace template symbols using template dictionary
287
+ // * create item in destination group
288
+ // * add created item's id into the template dictionary
289
+ const awaitAllItems = [];
290
+ const reuseItemsDef = _reuseDeployedItems(templates, options.enableItemReuse ?? false, templateDictionary, destinationAuthentication);
291
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
292
+ reuseItemsDef.then(() => {
293
+ const useExistingItemsDef = _useExistingItems(templates, common.getProp(templateDictionary, "params.useExisting"), templateDictionary, destinationAuthentication);
294
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
295
+ useExistingItemsDef.then(() => {
296
+ templates = common.setNamesAndTitles(templates, templateDictionary.solutionItemId);
297
+ buildOrder.forEach((id) => {
298
+ // Get the item's template out of the list of templates
299
+ const template = common.findTemplateInList(templates, id);
300
+ awaitAllItems.push(_createItemFromTemplateWhenReady(template, common.generateStorageFilePaths(portalSharingUrl, storageItemId, template.resources, options.storageVersion), storageAuthentication, templateDictionary, destinationAuthentication, itemProgressCallback));
301
+ });
302
+ // Wait until all items have been created
303
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
304
+ Promise.all(awaitAllItems).then((clonedSolutionItems) => {
305
+ if (failedTemplateItemIds.length === 0) {
306
+ // Do we have any items to be patched (i.e., they refer to dependencies using the template id rather
307
+ // than the cloned id because the item had to be created before the dependency)? Flag these items
308
+ // for post processing in the list of clones.
309
+ _flagPatchItemsForPostProcessing(itemsToBePatched, templateDictionary, clonedSolutionItems);
310
+ resolve(clonedSolutionItems);
311
+ }
312
+ else {
313
+ // Delete created items
314
+ const progressOptions = {
315
+ consoleProgress: true
316
+ };
317
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
318
+ common.deleteSolutionByComponents(deployedSolutionId, deployedItemIds, templates, templateDictionary, destinationAuthentication, progressOptions)
319
+ .then(() => reject(common.failWithIds(failedTemplateItemIds)));
320
+ }
321
+ });
322
+ });
323
+ }, e => {
324
+ console.error(e);
325
+ reject(common.fail(e));
326
+ });
327
+ });
328
+ }
329
+ /**
330
+ * For each item to be patched, convert it to its cloned id and mark the item as needing post processing.
331
+ *
332
+ * @param itemsToBePatched List of items that need to have their dependencies patched
333
+ * @param templateDictionary Hash of facts: org URL, adlib replacements
334
+ * @param templates A collection of AGO item templates
335
+ */
336
+ function _flagPatchItemsForPostProcessing(itemsToBePatched, templateDictionary, templates) {
337
+ let itemIdsToBePatched = Object.keys(itemsToBePatched);
338
+ /* istanbul ignore else */
339
+ if (itemIdsToBePatched.length > 0) {
340
+ // Replace the ids of the items to be patched (which are template ids) with their cloned versions
341
+ itemIdsToBePatched = itemIdsToBePatched.map(id => templateDictionary[id].itemId);
342
+ // Make sure that the items to be patched are flagged for post processing
343
+ templates.forEach(item => {
344
+ /* istanbul ignore else */
345
+ if (itemIdsToBePatched.includes(item.id)) {
346
+ item.postProcess = true;
347
+ }
348
+ });
349
+ }
350
+ }
351
+ /**
352
+ * Portal does not allow views of a single source to be created at the same time.
353
+ *
354
+ * Update view templates with an array of other view template ids that it should wait on.
355
+ *
356
+ * @param templates a collection of AGO item templates
357
+ *
358
+ * @returns An updated array of item templates
359
+ *
360
+ */
361
+ function _evaluateSharedViewSources(templates) {
362
+ // update the templates so we can defer the deployment when more than one view shares the same source
363
+ // these are not classic dependencies but are in some ways similar
364
+ const views = _getViews(templates);
365
+ _updateViewTemplates(templates, views);
366
+ const viewHash = _getViewHash(views);
367
+ let processed = [];
368
+ const visited = [];
369
+ Object.keys(viewHash).forEach(k => {
370
+ const _views = viewHash[k];
371
+ _views.forEach(cv => {
372
+ const template = common.findTemplateInList(templates, cv);
373
+ const syncViews = common.getProp(template, "properties.syncViews");
374
+ /* istanbul ignore else */
375
+ if (visited.indexOf(template.itemId) > -1) {
376
+ processed = processed.concat(syncViews);
377
+ }
378
+ /* istanbul ignore else */
379
+ if (syncViews && syncViews.length > 0) {
380
+ // when a view has multiple dependencies we need to retain the syncViews if they have been set already...
381
+ common.setProp(template, "properties.syncViews", common.cloneObject(processed));
382
+ }
383
+ /* istanbul ignore else */
384
+ if (processed.indexOf(cv) < 0) {
385
+ processed.push(cv);
386
+ }
387
+ /* istanbul ignore else */
388
+ if (visited.indexOf(template.itemId) < 0) {
389
+ visited.push(template.itemId);
390
+ }
391
+ });
392
+ processed = [];
393
+ });
394
+ return templates;
395
+ }
396
+ /**
397
+ * Add a syncViews array to each template that will hold all other view ids that
398
+ * have the same FS dependency.
399
+ * These arrays will be processed later to only contain ids that each view will need to wait on.
400
+ *
401
+ * @param templates a collection of AGO item templates
402
+ * @param views an array of view template details
403
+ *
404
+ * @returns An updated array of item templates
405
+ *
406
+ */
407
+ function _updateViewTemplates(templates, views) {
408
+ views.forEach(v => {
409
+ v.dependencies.forEach((id) => {
410
+ templates = templates.map(t => {
411
+ /* istanbul ignore else */
412
+ if (common.getProp(t, "properties.service.isView") &&
413
+ t.dependencies.indexOf(id) > -1 &&
414
+ t.itemId !== v.id) {
415
+ /* istanbul ignore else */
416
+ if (!Array.isArray(t.properties.syncViews)) {
417
+ t.properties.syncViews = [];
418
+ }
419
+ /* istanbul ignore else */
420
+ if (t.properties.syncViews.indexOf(v.id) < 0) {
421
+ t.properties.syncViews.push(v.id);
422
+ }
423
+ }
424
+ return t;
425
+ });
426
+ });
427
+ });
428
+ return templates;
429
+ }
430
+ /**
431
+ * Get all view templates from the source templates collection
432
+ *
433
+ * @param views A collection of view ID and dependencies
434
+ *
435
+ * @returns an array of objects with the source FS id as the key and a list of views that are
436
+ * dependant upon it
437
+ *
438
+ * @protected
439
+ */
440
+ function _getViewHash(views) {
441
+ const viewHash = {};
442
+ views.forEach(v => {
443
+ v.dependencies.forEach((d) => {
444
+ /* istanbul ignore else */
445
+ if (Object.keys(viewHash).indexOf(d) < 0) {
446
+ viewHash[d] = [v.id];
447
+ }
448
+ else if (viewHash[d].indexOf(v.id) < 0) {
449
+ viewHash[d].push(v.id);
450
+ }
451
+ });
452
+ });
453
+ return viewHash;
454
+ }
455
+ /**
456
+ * Get all view templates from the source templates collection
457
+ *
458
+ * @param templates A collection of AGO item templates
459
+ *
460
+ * @returns an array with the view id and its dependencies
461
+ *
462
+ * @protected
463
+ */
464
+ function _getViews(templates) {
465
+ return templates.reduce((acc, v) => {
466
+ /* istanbul ignore else */
467
+ if (common.getProp(v, "properties.service.isView")) {
468
+ acc.push({
469
+ id: v.itemId,
470
+ dependencies: v.dependencies
471
+ });
472
+ }
473
+ return acc;
474
+ }, []);
475
+ }
476
+ /**
477
+ * Search for existing items and update the templateDictionary with key details
478
+ *
479
+ * @param templates A collection of AGO item templates
480
+ * @param reuseItems Option to search for existing items
481
+ * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
482
+ * @param authentication Credentials for the requests
483
+ *
484
+ * @returns A Promise that will resolve once existing items have been evaluated
485
+ *
486
+ * @protected
487
+ */
488
+ function _reuseDeployedItems(templates, reuseItems, templateDictionary, authentication) {
489
+ return new Promise((resolve, reject) => {
490
+ if (reuseItems) {
491
+ const existingItemsByKeyword = _findExistingItemByKeyword(templates, templateDictionary, authentication);
492
+ Promise.all(existingItemsByKeyword).then((existingItemsByKeywordResponse) => {
493
+ const existingItemsByTag = _handleExistingItems(existingItemsByKeywordResponse, templateDictionary, authentication, true);
494
+ Promise.all(existingItemsByTag).then(existingItemsByTagResponse => {
495
+ _handleExistingItems(existingItemsByTagResponse, templateDictionary, authentication, false);
496
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
497
+ _updateTemplateDictionary(templates, templateDictionary, authentication).then(resolve);
498
+ }, e => reject(common.fail(e)));
499
+ }, e => reject(common.fail(e)));
500
+ }
501
+ else {
502
+ resolve(null);
503
+ }
504
+ });
505
+ }
506
+ /**
507
+ * Search for existing items and update the templateDictionary with key details
508
+ *
509
+ * Subtle difference between _reuseDeployedItems and _useExistingItems
510
+ * _reuseDeployedItems: will search all existing items based on specific type keywords
511
+ * that would have been added by a previous deployment
512
+ * _useExistingItems: will search for an existing item that the user provided
513
+ * the item id for while configuring in the deployment app.
514
+ * This type of item would not necessarily have been laid down by a previous deployment and
515
+ * can thus not expect that it will have the type keywords
516
+ *
517
+ * @param templates A collection of AGO item templates
518
+ * @param useExisting Option to search for existing items
519
+ * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
520
+ * @param authentication Credentials for the requests
521
+ *
522
+ * @returns A Promise that will resolve once existing items have been evaluated
523
+ *
524
+ * @protected
525
+ */
526
+ function _useExistingItems(templates, useExisting, templateDictionary, authentication) {
527
+ return new Promise(resolve => {
528
+ if (useExisting) {
529
+ const itemDefs = [];
530
+ const sourceIdHash = {};
531
+ const itemIds = [];
532
+ Object.keys(templateDictionary.params).forEach(k => {
533
+ const v = templateDictionary.params[k];
534
+ /* istanbul ignore else */
535
+ if (v.itemId && /[0-9A-F]{32}/i.test(k)) {
536
+ _updateTemplateDictionaryById(templateDictionary, k, v.itemId, v);
537
+ // need to check and set the typeKeyword if it doesn't exist on this service yet
538
+ // when the user has passed in an itemId that does not come from a previous deployment
539
+ itemDefs.push(common.getItemBase(v.itemId, authentication));
540
+ sourceIdHash[v.itemId] = k;
541
+ /* istanbul ignore else */
542
+ if (itemIds.indexOf(k) < 0) {
543
+ itemIds.push(k);
544
+ }
545
+ }
546
+ });
547
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
548
+ _setTypekeywordForExisting(itemDefs, sourceIdHash, authentication).then(() => {
549
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
550
+ _updateTemplateDictionary(itemIds.map(id => common.getTemplateById(templates, id)), templateDictionary, authentication).then(resolve);
551
+ });
552
+ }
553
+ else {
554
+ resolve(null);
555
+ }
556
+ });
557
+ }
558
+ /**
559
+ * Verify if the existing item has the source-<itemId> typeKeyword and set it if not
560
+ * This allows items that did not come from deployment to be found for reuse after they
561
+ * have been used once via a custom itemId param
562
+ *
563
+ * @param itemDefs
564
+ * @param sourceIdHash key value pairs..actual itemId is the key and the source itemId is the value
565
+ * @param authentication credentials for the requests
566
+ *
567
+ * @return a promise to indicate when the requests are complete
568
+ */
569
+ function _setTypekeywordForExisting(itemDefs, sourceIdHash, authentication) {
570
+ return new Promise(resolve => {
571
+ if (itemDefs.length > 0) {
572
+ Promise.all(itemDefs).then(results => {
573
+ const itemUpdateDefs = [];
574
+ results.forEach(result => {
575
+ const sourceId = sourceIdHash[result.id];
576
+ /* istanbul ignore else */
577
+ if (result && sourceId && result.typeKeywords) {
578
+ const sourceKeyword = `source-${sourceId}`;
579
+ const typeKeywords = result.typeKeywords;
580
+ /* istanbul ignore else */
581
+ if (typeKeywords.indexOf(sourceKeyword) < 0) {
582
+ typeKeywords.push(sourceKeyword);
583
+ const itemUpdate = { id: result.id, typeKeywords };
584
+ itemUpdateDefs.push(common.updateItem(itemUpdate, authentication));
585
+ }
586
+ }
587
+ });
588
+ // wait for updates to finish before we resolve
589
+ if (itemUpdateDefs.length > 0) {
590
+ Promise.all(itemUpdateDefs).then(resolve, () => resolve(undefined));
591
+ }
592
+ else {
593
+ resolve(undefined);
594
+ }
595
+ }, () => resolve(undefined));
596
+ }
597
+ else {
598
+ resolve(undefined);
599
+ }
600
+ });
601
+ }
602
+ /**
603
+ * Update the templateDictionary with key details by item type
604
+ *
605
+ * @param templates A collection of AGO item templates
606
+ * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
607
+ *
608
+ * @protected
609
+ */
610
+ function _updateTemplateDictionary(templates, templateDictionary, authentication) {
611
+ return new Promise(resolve => {
612
+ const defs = [];
613
+ const urls = [];
614
+ const types = [];
615
+ const ids = [];
616
+ templates.forEach(t => {
617
+ const templateInfo = templateDictionary[t.itemId];
618
+ /* istanbul ignore else */
619
+ if (templateInfo && templateInfo.url && templateInfo.itemId) {
620
+ /* istanbul ignore else */
621
+ if (t.item.type === "Feature Service") {
622
+ const enterpriseIDMapping = common.getProp(templateDictionary, `params.${t.itemId}.enterpriseIDMapping`);
623
+ Object.assign(templateDictionary[t.itemId], common.getLayerSettings(common.getLayersAndTables(t), templateInfo.url, templateInfo.itemId, enterpriseIDMapping));
624
+ // if the service has veiws keep track of the fields so we can use them to
625
+ // compare with the view fields
626
+ /* istanbul ignore else */
627
+ if (common.getProp(t, "properties.service.hasViews")) {
628
+ common._updateTemplateDictionaryFields(t, templateDictionary, false);
629
+ }
630
+ }
631
+ // for fs query with its url...for non fs query the item
632
+ // this is to verify situations where we have a stale search index that will
633
+ // say some items exist when they don't really exist
634
+ // searching the services url or with the item id will return an error when this condition occurs
635
+ /* istanbul ignore else */
636
+ if (urls.indexOf(templateInfo.url) < 0) {
637
+ defs.push(t.item.type === "Feature Service"
638
+ ? common.rest_request(templateInfo.url, { authentication })
639
+ : common.getItemBase(templateInfo.itemId, authentication));
640
+ urls.push(templateInfo.url);
641
+ types.push(t.item.type);
642
+ ids.push(templateInfo.itemId);
643
+ }
644
+ }
645
+ });
646
+ if (defs.length > 0) {
647
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
648
+ Promise.all(defs.map(p => p.catch(e => e))).then(results => {
649
+ /* istanbul ignore else */
650
+ if (Array.isArray(results) && results.length > 0) {
651
+ const fieldDefs = [];
652
+ results.forEach((r, i) => {
653
+ // a feature service result will contain a serviceItemId if it was successfully fetched
654
+ if (r.serviceItemId && types[i] === "Feature Service") {
655
+ Object.keys(templateDictionary).forEach(k => {
656
+ const v = templateDictionary[k];
657
+ /* istanbul ignore else */
658
+ if (v.itemId && v.itemId === r.serviceItemId) {
659
+ common.setDefaultSpatialReference(templateDictionary, k, r.spatialReference);
660
+ // keep the extent values from these responses as well
661
+ common.setCreateProp(templateDictionary, `${k}.defaultExtent`, r.fullExtent || r.initialExtent);
662
+ const layerIds = (r.layers || []).map((l) => l.id);
663
+ const tablesIds = (r.tables || []).map((t) => t.id);
664
+ fieldDefs.push(common.getExistingLayersAndTables(urls[i], layerIds.concat(tablesIds), authentication));
665
+ }
666
+ });
667
+ }
668
+ else {
669
+ /* istanbul ignore else */
670
+ if (types[i] === "Feature Service" ||
671
+ common.getProp(r, "response.error")) {
672
+ // if an error is returned we need to clean up the templateDictionary
673
+ templateDictionary = _updateTemplateDictionaryForError(templateDictionary, ids[i]);
674
+ }
675
+ }
676
+ });
677
+ if (fieldDefs.length > 0) {
678
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
679
+ Promise.all(fieldDefs).then(layerTableResult => {
680
+ layerTableResult.forEach(l => {
681
+ l.forEach((ll) => {
682
+ Object.keys(templateDictionary).forEach(k => {
683
+ /* istanbul ignore else */
684
+ if (templateDictionary[k].itemId === ll.serviceItemId) {
685
+ let sourceId = "";
686
+ Object.keys(templateDictionary).some(_k => {
687
+ /* istanbul ignore else */
688
+ if (templateDictionary[_k].itemId === ll.serviceItemId) {
689
+ sourceId = _k;
690
+ return true;
691
+ }
692
+ });
693
+ const enterpriseIDMapping = common.getProp(templateDictionary, `params.${sourceId}.enterpriseIDMapping`);
694
+ if (enterpriseIDMapping) {
695
+ Object.keys(enterpriseIDMapping).forEach(id => {
696
+ if (enterpriseIDMapping[id].toString() ===
697
+ ll.id.toString()) {
698
+ _setFields(templateDictionary, k, id, ll.fields);
699
+ }
700
+ });
701
+ }
702
+ else {
703
+ _setFields(templateDictionary, k, ll.id, ll.fields);
704
+ }
705
+ }
706
+ });
707
+ });
708
+ });
709
+ resolve(null);
710
+ });
711
+ }
712
+ else {
713
+ resolve(null);
714
+ }
715
+ }
716
+ else {
717
+ resolve(null);
718
+ }
719
+ });
720
+ }
721
+ else {
722
+ resolve(null);
723
+ }
724
+ });
725
+ }
726
+ /**
727
+ * Add the fields from the source layer to the template dictionary for any required replacements
728
+ *
729
+ * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
730
+ * @param itemId the id for the item
731
+ * @param layerId the id for the layer
732
+ * @param fields the fields to transfer
733
+ *
734
+ * @protected
735
+ */
736
+ function _setFields(templateDictionary, itemId, layerId, fields) {
737
+ const layerInfo = common.getProp(templateDictionary, `${itemId}.layer${layerId}`);
738
+ /* istanbul ignore else */
739
+ if (layerInfo && fields) {
740
+ layerInfo.fields = fields;
741
+ }
742
+ }
743
+ /**
744
+ * In some cases an item id search will return a stale item reference
745
+ * it will subsequently fail when we try to fetch the underlying service.
746
+ *
747
+ * We need to remove the item info that has been added to the template dictionary
748
+ * and treat the item as we do other items that don't already exist on deployment.
749
+ *
750
+ * @param result the service request result
751
+ * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
752
+ *
753
+ * @protected
754
+ */
755
+ function _updateTemplateDictionaryForError(templateDictionary, itemId) {
756
+ /* istanbul ignore else */
757
+ if (itemId) {
758
+ let removeKey = "";
759
+ Object.keys(templateDictionary).some(k => {
760
+ /* istanbul ignore else */
761
+ if (templateDictionary[k].itemId === itemId) {
762
+ removeKey = k;
763
+ return true;
764
+ }
765
+ });
766
+ /* istanbul ignore else */
767
+ if (removeKey !== "") {
768
+ delete templateDictionary[removeKey];
769
+ }
770
+ }
771
+ return templateDictionary;
772
+ }
773
+ /**
774
+ * Optionally search by tags and then update the templateDictionary based on the search results
775
+ *
776
+ * @param existingItemsResponse response object from search by typeKeyword and type
777
+ * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
778
+ * @param authentication Credentials for the request
779
+ * @param addTagQuery Boolean to indicate if a search by tag should happen
780
+ * @return A promise that will resolve with an array of results
781
+ * @protected
782
+ */
783
+ function _handleExistingItems(existingItemsResponse, templateDictionary, authentication, addTagQuery) {
784
+ // if items are not found by type keyword search by tag
785
+ const existingItemsByTag = [Promise.resolve(null)];
786
+ /* istanbul ignore else */
787
+ if (existingItemsResponse && Array.isArray(existingItemsResponse)) {
788
+ existingItemsResponse.forEach(existingItem => {
789
+ /* istanbul ignore else */
790
+ if (Array.isArray(existingItem?.results)) {
791
+ let result;
792
+ const results = existingItem.results;
793
+ if (results.length === 1) {
794
+ result = results[0];
795
+ }
796
+ else if (results.length > 1) {
797
+ result = results.reduce((a, b) => a.created > b.created ? a : b);
798
+ }
799
+ else {
800
+ if (addTagQuery && existingItem.query) {
801
+ const tagQuery = existingItem.query.replace("typekeywords", "tags");
802
+ existingItemsByTag.push(_findExistingItem(tagQuery, authentication));
803
+ }
804
+ }
805
+ if (result) {
806
+ const sourceId = existingItem.query
807
+ ? existingItem.query.match(/[0-9A-F]{32}/i)[0]
808
+ : existingItem.sourceId;
809
+ /* istanbul ignore else */
810
+ if (sourceId) {
811
+ _updateTemplateDictionaryById(templateDictionary, sourceId, result.id, result);
812
+ }
813
+ }
814
+ }
815
+ });
816
+ }
817
+ return existingItemsByTag;
818
+ }
819
+ function _updateTemplateDictionaryById(templateDictionary, sourceId, itemId, v) {
820
+ templateDictionary[sourceId] = Object.assign(templateDictionary[sourceId] || {}, {
821
+ def: Promise.resolve(common.generateEmptyCreationResponse(v.type, itemId)),
822
+ itemId,
823
+ name: v.name,
824
+ title: v.title,
825
+ url: v.url
826
+ });
827
+ }
828
+ /**
829
+ * Search items based on user query
830
+ *
831
+ * @param query Query string to use
832
+ * @param authentication Credentials for the request
833
+ * @return A promise that will resolve with an array of results
834
+ * @protected
835
+ */
836
+ function _findExistingItemByKeyword(templates, templateDictionary, authentication) {
837
+ const existingItemsDefs = [];
838
+ templates.forEach(template => {
839
+ if (template.item.type === "Group") {
840
+ const userGroups = templateDictionary.user?.groups;
841
+ /* istanbul ignore else */
842
+ if (Array.isArray(userGroups)) {
843
+ existingItemsDefs.push(Promise.resolve({
844
+ results: userGroups
845
+ .filter(g => g.tags.indexOf(`source-${template.itemId}`) > -1)
846
+ .map(g => {
847
+ g.type = "Group";
848
+ return g;
849
+ }),
850
+ sourceId: template.itemId
851
+ }));
852
+ }
853
+ }
854
+ else {
855
+ existingItemsDefs.push(_findExistingItem(`typekeywords:source-${template.itemId} type:${template.item.type} owner:${templateDictionary.user.username}`, authentication));
856
+ }
857
+ });
858
+ return existingItemsDefs;
859
+ }
860
+ /**
861
+ * Search items based on user query
862
+ *
863
+ * @param query Query string to use
864
+ * @param authentication Credentials for the request
865
+ * @return A promise that will resolve with an array of results
866
+ * @protected
867
+ */
868
+ function _findExistingItem(query, authentication) {
869
+ const searchOptions = {
870
+ q: query,
871
+ authentication: authentication,
872
+ pagingParam: { start: 1, num: 100 }
873
+ };
874
+ return common.searchItems(searchOptions);
875
+ }
876
+ /**
877
+ * Creates an item from a template once the item's dependencies have been created.
878
+ *
879
+ * @param template Template of item to deploy
880
+ * @param resourceFilePaths URL, folder, and filename for each item resource/metadata/thumbnail
881
+ * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
882
+ * @param userSession Options for the request
883
+ * @param itemProgressCallback Function for reporting progress updates from type-specific template handlers
884
+ * @return A promise that will resolve with the id of the deployed item (which is simply returned if it's
885
+ * already in the templates list
886
+ * @protected
887
+ */
888
+ function _createItemFromTemplateWhenReady(template, resourceFilePaths, storageAuthentication, templateDictionary, destinationAuthentication, itemProgressCallback) {
889
+ // ensure this is present
890
+ template.dependencies = template.dependencies || [];
891
+ // if there is no entry in the templateDictionary
892
+ // or if we have a basic entry without the deferred request for its creation, add it
893
+ if (!templateDictionary.hasOwnProperty(template.itemId) ||
894
+ !common.getProp(templateDictionary[template.itemId], "def")) {
895
+ let createResponse;
896
+ let statusCode = common.EItemProgressStatus.Unknown;
897
+ let itemHandler;
898
+ templateDictionary[template.itemId] =
899
+ templateDictionary[template.itemId] || {};
900
+ // Save the deferred for the use of items that depend on this item being created first
901
+ templateDictionary[template.itemId].def = new Promise(resolve => {
902
+ // Wait until all of the item's dependencies are deployed
903
+ const _awaitDependencies = template.dependencies.reduce((acc, id) => {
904
+ const def = common.getProp(templateDictionary, `${id}.def`);
905
+ // can't use maybePush as that clones the object, which does not work for Promises
906
+ /* istanbul ignore else */
907
+ if (def) {
908
+ acc.push(def);
909
+ }
910
+ return acc;
911
+ }, []);
912
+ const syncViews = common.getProp(template, "properties.syncViews");
913
+ const awaitDependencies = syncViews && syncViews.length > 0
914
+ ? syncViews.reduce((acc, v) => {
915
+ const def = common.getProp(templateDictionary, `${v}.def`);
916
+ /* istanbul ignore else */
917
+ if (def) {
918
+ acc.push(def);
919
+ }
920
+ return acc;
921
+ }, _awaitDependencies)
922
+ : _awaitDependencies;
923
+ Promise.all(awaitDependencies)
924
+ .then(() => {
925
+ // Find the conversion handler for this item type
926
+ const templateType = template.type;
927
+ itemHandler = moduleMap[templateType];
928
+ if (!itemHandler || itemHandler === UNSUPPORTED$1) {
929
+ if (itemHandler === UNSUPPORTED$1) {
930
+ statusCode = common.EItemProgressStatus.Ignored;
931
+ throw new Error();
932
+ }
933
+ else {
934
+ statusCode = common.EItemProgressStatus.Failed;
935
+ throw new Error();
936
+ }
937
+ }
938
+ // Get the item's thumbnail
939
+ return common.getThumbnailFromStorageItem(storageAuthentication, resourceFilePaths);
940
+ })
941
+ .then(thumbnail => {
942
+ template.item.thumbnail = thumbnail;
943
+ // Delegate the creation of the item to the handler
944
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
945
+ return itemHandler.createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback);
946
+ })
947
+ .then((response) => {
948
+ if (response.id === "") {
949
+ statusCode = common.EItemProgressStatus.Failed;
950
+ throw new Error("handled"); // fails to create item
951
+ }
952
+ /* istanbul ignore else */
953
+ createResponse = response;
954
+ if (createResponse.item.item.url) {
955
+ common.setCreateProp(templateDictionary, template.itemId + ".url", createResponse.item.item.url);
956
+ }
957
+ if (resourceFilePaths.length > 0) {
958
+ // Copy resources, metadata, form
959
+ return common.copyFilesFromStorageItem(storageAuthentication, resourceFilePaths, templateDictionary.folderId, createResponse.id, destinationAuthentication, createResponse.item);
960
+ }
961
+ else {
962
+ return Promise.resolve(null);
963
+ }
964
+ })
965
+ .then(() => {
966
+ resolve(createResponse);
967
+ })
968
+ .catch(error => {
969
+ if (!error || error.message !== "handled") {
970
+ itemProgressCallback(template.itemId, statusCode === common.EItemProgressStatus.Unknown
971
+ ? common.EItemProgressStatus.Failed
972
+ : statusCode, 0);
973
+ }
974
+ // Item type not supported or fails to get item dependencies
975
+ resolve(common.generateEmptyCreationResponse(template.type));
976
+ });
977
+ });
978
+ }
979
+ return templateDictionary[template.itemId].def;
980
+ }
981
+ /**
982
+ * Accumulates the estimated deployment cost of a set of templates.
983
+ *
984
+ * @param templates Templates to examine
985
+ * @return Sum of estimated deployment costs
986
+ * @protected
987
+ */
988
+ function _estimateDeploymentCost(templates) {
989
+ return templates.reduce((accumulatedEstimatedCost, template) => {
990
+ return (accumulatedEstimatedCost + (template.estimatedDeploymentCostFactor || 1));
991
+ }, 0);
992
+ }
993
+ // TODO: Return a Promise vs array of promises
994
+ function _getGroupUpdates(template, authentication, templateDictionary) {
995
+ const groups = template.groups || [];
996
+ return groups.map((sourceGroupId) => {
997
+ return common.shareItem(templateDictionary[sourceGroupId].itemId, template.itemId, authentication, common.isTrackingViewTemplate(template) ? templateDictionary.locationTracking.owner : undefined);
998
+ });
999
+ }
254
1000
 
255
- /** @license
256
- * Copyright 2018 Esri
257
- *
258
- * Licensed under the Apache License, Version 2.0 (the "License");
259
- * you may not use this file except in compliance with the License.
260
- * You may obtain a copy of the License at
261
- *
262
- * http://www.apache.org/licenses/LICENSE-2.0
263
- *
264
- * Unless required by applicable law or agreed to in writing, software
265
- * distributed under the License is distributed on an "AS IS" BASIS,
266
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
267
- * See the License for the specific language governing permissions and
268
- * limitations under the License.
269
- */
270
- var UNSUPPORTED$1 = null;
271
- // ------------------------------------------------------------------------------------------------------------------ //
272
- /**
273
- * Deploys a set of items defined by templates.
274
- *
275
- * @param portalSharingUrl Server/sharing
276
- * @param storageItemId Id of storage item
277
- * @param templates A collection of AGO item templates
278
- * @param storageAuthentication Credentials for the organization with the source items
279
- * @param templateDictionary Hash of facts: org URL, adlib replacements
280
- * @param destinationAuthentication Credentials for the destination organization
281
- * @param options Options to tune deployment
282
- * @return A promise that will resolve with the list of information about the created items
283
- */
284
- function deploySolutionItems(portalSharingUrl, storageItemId, templates, storageAuthentication, templateDictionary, destinationAuthentication, options) {
285
- return new Promise(function (resolve, reject) {
286
- var _a;
287
- // Prepare feedback mechanism
288
- var totalEstimatedCost = _estimateDeploymentCost(templates) + 1; // solution items, plus avoid divide by 0
289
- var percentDone = 10; // allow for previous deployment work
290
- var progressPercentStep = (99 - percentDone) / totalEstimatedCost; // leave some % for caller for wrapup
291
- var failedTemplateItemIds = [];
292
- var deployedItemIds = [];
293
- var statusOK = true;
294
- // TODO: move to separate fn
295
- var itemProgressCallback = function (itemId, status, costUsed, createdItemId // supplied when status is EItemProgressStatus.Created or .Finished
296
- ) {
297
- var _a;
298
- percentDone += progressPercentStep * costUsed;
299
- /* istanbul ignore else */
300
- if (options.progressCallback) {
301
- if (status === common.EItemProgressStatus.Finished) {
302
- var event_1 = {
303
- event: common.SItemProgressStatus[status],
304
- data: itemId
305
- };
306
- options.progressCallback(Math.round(percentDone), options.jobId, event_1);
307
- }
308
- else {
309
- options.progressCallback(Math.round(percentDone), options.jobId);
310
- }
311
- }
312
- /* istanbul ignore if */
313
- if (options.consoleProgress) {
314
- console.log(Date.now(), itemId, (_a = options.jobId) !== null && _a !== void 0 ? _a : "", common.SItemProgressStatus[status], percentDone.toFixed(0) + "%", costUsed, createdItemId ? "==> " + createdItemId : "");
315
- }
316
- if (status === common.EItemProgressStatus.Created) {
317
- deployedItemIds.push(createdItemId);
318
- }
319
- else if (status === common.EItemProgressStatus.Failed) {
320
- failedTemplateItemIds.push(itemId);
321
- console.error("Item " + itemId + " has failed");
322
- statusOK = false;
323
- }
324
- return statusOK;
325
- // ---------------------------------------------------------------------------------------------------------------
326
- };
327
- // portal does not allow views of a single source to be created at the same time
328
- if (common.getProp(templateDictionary, "organization.isPortal")) {
329
- templates = _evaluateSharedViewSources(templates);
330
- }
331
- // Create an ordered graph of the templates so that dependencies are created before the items that need them.
332
- // Because cycles are permitted, we also keep track of items that need to be patched later because their
333
- // dependencies are necessarily created after they are created.
334
- var _b = common.topologicallySortItems(templates), buildOrder = _b.buildOrder, itemsToBePatched = _b.itemsToBePatched;
335
- // For each item in order from no dependencies to dependent on other items,
336
- // * replace template symbols using template dictionary
337
- // * create item in destination group
338
- // * add created item's id into the template dictionary
339
- var awaitAllItems = [];
340
- var reuseItemsDef = _reuseDeployedItems(templates, (_a = options.enableItemReuse) !== null && _a !== void 0 ? _a : false, templateDictionary, destinationAuthentication);
341
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
342
- reuseItemsDef.then(function () {
343
- var useExistingItemsDef = _useExistingItems(templates, common.getProp(templateDictionary, "params.useExisting"), templateDictionary, destinationAuthentication);
344
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
345
- useExistingItemsDef.then(function () {
346
- templates = common.setNamesAndTitles(templates, templateDictionary.solutionItemId);
347
- buildOrder.forEach(function (id) {
348
- // Get the item's template out of the list of templates
349
- var template = common.findTemplateInList(templates, id);
350
- awaitAllItems.push(_createItemFromTemplateWhenReady(template, common.generateStorageFilePaths(portalSharingUrl, storageItemId, template.resources, options.storageVersion), storageAuthentication, templateDictionary, destinationAuthentication, itemProgressCallback));
351
- });
352
- // Wait until all items have been created
353
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
354
- Promise.all(awaitAllItems).then(function (clonedSolutionItems) {
355
- if (failedTemplateItemIds.length === 0) {
356
- // Do we have any items to be patched (i.e., they refer to dependencies using the template id rather
357
- // than the cloned id because the item had to be created before the dependency)? Flag these items
358
- // for post processing in the list of clones.
359
- _flagPatchItemsForPostProcessing(itemsToBePatched, templateDictionary, clonedSolutionItems);
360
- resolve(clonedSolutionItems);
361
- }
362
- else {
363
- // Delete created items
364
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
365
- common.removeListOfItemsOrGroups(deployedItemIds, destinationAuthentication)
366
- .then(function () {
367
- return reject(common.failWithIds(failedTemplateItemIds));
368
- });
369
- }
370
- });
371
- });
372
- }, function (e) {
373
- console.error(e);
374
- reject(common.fail(e));
375
- });
376
- });
377
- }
378
- /**
379
- * For each item to be patched, convert it to its cloned id and mark the item as needing post processing.
380
- *
381
- * @param itemsToBePatched List of items that need to have their dependencies patched
382
- * @param templateDictionary Hash of facts: org URL, adlib replacements
383
- * @param templates A collection of AGO item templates
384
- */
385
- function _flagPatchItemsForPostProcessing(itemsToBePatched, templateDictionary, templates) {
386
- var itemIdsToBePatched = Object.keys(itemsToBePatched);
387
- /* istanbul ignore else */
388
- if (itemIdsToBePatched.length > 0) {
389
- // Replace the ids of the items to be patched (which are template ids) with their cloned versions
390
- itemIdsToBePatched = itemIdsToBePatched.map(function (id) { return templateDictionary[id].itemId; });
391
- // Make sure that the items to be patched are flagged for post processing
392
- templates.forEach(function (item) {
393
- /* istanbul ignore else */
394
- if (itemIdsToBePatched.includes(item.id)) {
395
- item.postProcess = true;
396
- }
397
- });
398
- }
399
- }
400
- /**
401
- * Portal does not allow views of a single source to be created at the same time.
402
- *
403
- * Update view templates with an array of other view template ids that it should wait on.
404
- *
405
- * @param templates a collection of AGO item templates
406
- *
407
- * @returns An updated array of item templates
408
- *
409
- */
410
- function _evaluateSharedViewSources(templates) {
411
- // update the templates so we can defer the deployment when more than one view shares the same source
412
- // these are not classic dependencies but are in some ways similar
413
- var views = _getViews(templates);
414
- _updateViewTemplates(templates, views);
415
- var viewHash = _getViewHash(views);
416
- var processed = [];
417
- var visited = [];
418
- Object.keys(viewHash).forEach(function (k) {
419
- var _views = viewHash[k];
420
- _views.forEach(function (cv) {
421
- var template = common.findTemplateInList(templates, cv);
422
- var syncViews = common.getProp(template, "properties.syncViews");
423
- /* istanbul ignore else */
424
- if (visited.indexOf(template.itemId) > -1) {
425
- processed = processed.concat(syncViews);
426
- }
427
- /* istanbul ignore else */
428
- if (syncViews && syncViews.length > 0) {
429
- // when a view has multiple dependencies we need to retain the syncViews if they have been set already...
430
- common.setProp(template, "properties.syncViews", common.cloneObject(processed));
431
- }
432
- /* istanbul ignore else */
433
- if (processed.indexOf(cv) < 0) {
434
- processed.push(cv);
435
- }
436
- /* istanbul ignore else */
437
- if (visited.indexOf(template.itemId) < 0) {
438
- visited.push(template.itemId);
439
- }
440
- });
441
- processed = [];
442
- });
443
- return templates;
444
- }
445
- /**
446
- * Add a syncViews array to each template that will hold all other view ids that
447
- * have the same FS dependency.
448
- * These arrays will be processed later to only contain ids that each view will need to wait on.
449
- *
450
- * @param templates a collection of AGO item templates
451
- * @param views an array of view template details
452
- *
453
- * @returns An updated array of item templates
454
- *
455
- */
456
- function _updateViewTemplates(templates, views) {
457
- views.forEach(function (v) {
458
- v.dependencies.forEach(function (id) {
459
- templates = templates.map(function (t) {
460
- /* istanbul ignore else */
461
- if (common.getProp(t, "properties.service.isView") &&
462
- t.dependencies.indexOf(id) > -1 &&
463
- t.itemId !== v.id) {
464
- /* istanbul ignore else */
465
- if (!Array.isArray(t.properties.syncViews)) {
466
- t.properties.syncViews = [];
467
- }
468
- /* istanbul ignore else */
469
- if (t.properties.syncViews.indexOf(v.id) < 0) {
470
- t.properties.syncViews.push(v.id);
471
- }
472
- }
473
- return t;
474
- });
475
- });
476
- });
477
- return templates;
478
- }
479
- /**
480
- * Get all view templates from the source templates collection
481
- *
482
- * @param views A collection of view ID and dependencies
483
- *
484
- * @returns an array of objects with the source FS id as the key and a list of views that are
485
- * dependant upon it
486
- *
487
- * @protected
488
- */
489
- function _getViewHash(views) {
490
- var viewHash = {};
491
- views.forEach(function (v) {
492
- v.dependencies.forEach(function (d) {
493
- /* istanbul ignore else */
494
- if (Object.keys(viewHash).indexOf(d) < 0) {
495
- viewHash[d] = [v.id];
496
- }
497
- else if (viewHash[d].indexOf(v.id) < 0) {
498
- viewHash[d].push(v.id);
499
- }
500
- });
501
- });
502
- return viewHash;
503
- }
504
- /**
505
- * Get all view templates from the source templates collection
506
- *
507
- * @param templates A collection of AGO item templates
508
- *
509
- * @returns an array with the view id and its dependencies
510
- *
511
- * @protected
512
- */
513
- function _getViews(templates) {
514
- return templates.reduce(function (acc, v) {
515
- /* istanbul ignore else */
516
- if (common.getProp(v, "properties.service.isView")) {
517
- acc.push({
518
- id: v.itemId,
519
- dependencies: v.dependencies
520
- });
521
- }
522
- return acc;
523
- }, []);
524
- }
525
- /**
526
- * Search for existing items and update the templateDictionary with key details
527
- *
528
- * @param templates A collection of AGO item templates
529
- * @param reuseItems Option to search for existing items
530
- * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
531
- * @param authentication Credentials for the requests
532
- *
533
- * @returns A Promise that will resolve once existing items have been evaluated
534
- *
535
- * @protected
536
- */
537
- function _reuseDeployedItems(templates, reuseItems, templateDictionary, authentication) {
538
- return new Promise(function (resolve, reject) {
539
- if (reuseItems) {
540
- var existingItemsByKeyword = _findExistingItemByKeyword(templates, templateDictionary, authentication);
541
- Promise.all(existingItemsByKeyword).then(function (existingItemsByKeywordResponse) {
542
- var existingItemsByTag = _handleExistingItems(existingItemsByKeywordResponse, templateDictionary, authentication, true);
543
- Promise.all(existingItemsByTag).then(function (existingItemsByTagResponse) {
544
- _handleExistingItems(existingItemsByTagResponse, templateDictionary, authentication, false);
545
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
546
- _updateTemplateDictionary(templates, templateDictionary, authentication).then(resolve);
547
- }, function (e) { return reject(common.fail(e)); });
548
- }, function (e) { return reject(common.fail(e)); });
549
- }
550
- else {
551
- resolve(null);
552
- }
553
- });
554
- }
555
- /**
556
- * Search for existing items and update the templateDictionary with key details
557
- *
558
- * Subtle difference between _reuseDeployedItems and _useExistingItems
559
- * _reuseDeployedItems: will search all existing items based on specific type keywords
560
- * that would have been added by a previous deployment
561
- * _useExistingItems: will search for an existing item that the user provided
562
- * the item id for while configuring in the deployment app.
563
- * This type of item would not necessarily have been laid down by a previous deployment and
564
- * can thus not expect that it will have the type keywords
565
- *
566
- * @param templates A collection of AGO item templates
567
- * @param useExisting Option to search for existing items
568
- * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
569
- * @param authentication Credentials for the requests
570
- *
571
- * @returns A Promise that will resolve once existing items have been evaluated
572
- *
573
- * @protected
574
- */
575
- function _useExistingItems(templates, useExisting, templateDictionary, authentication) {
576
- return new Promise(function (resolve) {
577
- if (useExisting) {
578
- var itemIds_1 = [];
579
- Object.keys(templateDictionary.params).forEach(function (k) {
580
- var v = templateDictionary.params[k];
581
- /* istanbul ignore else */
582
- if (v.itemId && v.sourceId) {
583
- _updateTemplateDictionaryById(templateDictionary, v.sourceId, v.itemId, v);
584
- /* istanbul ignore else */
585
- if (itemIds_1.indexOf(v.sourceId) < 0) {
586
- itemIds_1.push(v.sourceId);
587
- }
588
- }
589
- });
590
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
591
- _updateTemplateDictionary(itemIds_1.map(function (id) { return common.getTemplateById(templates, id); }), templateDictionary, authentication).then(resolve);
592
- }
593
- else {
594
- resolve(null);
595
- }
596
- });
597
- }
598
- /**
599
- * Update the templateDictionary with key details by item type
600
- *
601
- * @param templates A collection of AGO item templates
602
- * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
603
- *
604
- * @protected
605
- */
606
- function _updateTemplateDictionary(templates, templateDictionary, authentication) {
607
- return new Promise(function (resolve) {
608
- var defs = [];
609
- var urls = [];
610
- var types = [];
611
- var ids = [];
612
- templates.forEach(function (t) {
613
- var templateInfo = templateDictionary[t.itemId];
614
- /* istanbul ignore else */
615
- if (templateInfo && templateInfo.url && templateInfo.itemId) {
616
- /* istanbul ignore else */
617
- if (t.item.type === "Feature Service") {
618
- Object.assign(templateDictionary[t.itemId], common.getLayerSettings(common.getLayersAndTables(t), templateInfo.url, templateInfo.itemId));
619
- // if the service has veiws keep track of the fields so we can use them to
620
- // compare with the view fields
621
- /* istanbul ignore else */
622
- if (common.getProp(t, "properties.service.hasViews")) {
623
- common._updateTemplateDictionaryFields(t, templateDictionary, false);
624
- }
625
- }
626
- // for fs query with its url...for non fs query the item
627
- // this is to verify situations where we have a stale search index that will
628
- // say some items exist when they don't really exist
629
- // searching the services url or with the item id will return an error when this condition occurs
630
- /* istanbul ignore else */
631
- if (urls.indexOf(templateInfo.url) < 0) {
632
- defs.push(t.item.type === "Feature Service"
633
- ? common.rest_request(templateInfo.url, { authentication: authentication })
634
- : common.getItemBase(templateInfo.itemId, authentication));
635
- urls.push(templateInfo.url);
636
- types.push(t.item.type);
637
- ids.push(templateInfo.itemId);
638
- }
639
- }
640
- });
641
- if (defs.length > 0) {
642
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
643
- Promise.all(defs.map(function (p) { return p.catch(function (e) { return e; }); })).then(function (results) {
644
- /* istanbul ignore else */
645
- if (Array.isArray(results) && results.length > 0) {
646
- var fieldDefs_1 = [];
647
- results.forEach(function (r, i) {
648
- // a feature service result will contain a serviceItemId if it was successfully fetched
649
- if (r.serviceItemId && types[i] === "Feature Service") {
650
- Object.keys(templateDictionary).forEach(function (k) {
651
- var v = templateDictionary[k];
652
- /* istanbul ignore else */
653
- if (v.itemId && v.itemId === r.serviceItemId) {
654
- common.setDefaultSpatialReference(templateDictionary, k, r.spatialReference);
655
- // keep the extent values from these responses as well
656
- common.setCreateProp(templateDictionary, k + ".defaultExtent", r.fullExtent || r.initialExtent);
657
- var layerIds = (r.layers || []).map(function (l) { return l.id; });
658
- var tablesIds = (r.tables || []).map(function (t) { return t.id; });
659
- fieldDefs_1.push(common.getExistingLayersAndTables(urls[i], layerIds.concat(tablesIds), authentication));
660
- }
661
- });
662
- }
663
- else {
664
- /* istanbul ignore else */
665
- if (types[i] === "Feature Service" ||
666
- common.getProp(r, "response.error")) {
667
- // if an error is returned we need to clean up the templateDictionary
668
- templateDictionary = _updateTemplateDictionaryForError(templateDictionary, ids[i]);
669
- }
670
- }
671
- });
672
- if (fieldDefs_1.length > 0) {
673
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
674
- Promise.all(fieldDefs_1).then(function (layerTableResult) {
675
- layerTableResult.forEach(function (l) {
676
- l.forEach(function (ll) {
677
- Object.keys(templateDictionary).forEach(function (k) {
678
- /* istanbul ignore else */
679
- if (templateDictionary[k].itemId === ll.serviceItemId) {
680
- var layerInfo = common.getProp(templateDictionary, k + ".layer" + ll.id);
681
- /* istanbul ignore else */
682
- if (layerInfo && ll.fields) {
683
- layerInfo.fields = ll.fields;
684
- }
685
- }
686
- });
687
- });
688
- });
689
- resolve(null);
690
- });
691
- }
692
- else {
693
- resolve(null);
694
- }
695
- }
696
- else {
697
- resolve(null);
698
- }
699
- });
700
- }
701
- else {
702
- resolve(null);
703
- }
704
- });
705
- }
706
- /**
707
- * In some cases an item id search will return a stale item reference
708
- * it will subsequently fail when we try to fetch the underlying service.
709
- *
710
- * We need to remove the item info that has been added to the template dictionary
711
- * and treat the item as we do other items that don't already exist on deployment.
712
- *
713
- * @param result the service request result
714
- * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
715
- *
716
- * @protected
717
- */
718
- function _updateTemplateDictionaryForError(templateDictionary, itemId) {
719
- /* istanbul ignore else */
720
- if (itemId) {
721
- var removeKey_1 = "";
722
- Object.keys(templateDictionary).some(function (k) {
723
- /* istanbul ignore else */
724
- if (templateDictionary[k].itemId === itemId) {
725
- removeKey_1 = k;
726
- return true;
727
- }
728
- });
729
- /* istanbul ignore else */
730
- if (removeKey_1 !== "") {
731
- delete templateDictionary[removeKey_1];
732
- }
733
- }
734
- return templateDictionary;
735
- }
736
- /**
737
- * Optionally search by tags and then update the templateDictionary based on the search results
738
- *
739
- * @param existingItemsResponse response object from search by typeKeyword and type
740
- * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
741
- * @param authentication Credentials for the request
742
- * @param addTagQuery Boolean to indicate if a search by tag should happen
743
- * @return A promise that will resolve with an array of results
744
- * @protected
745
- */
746
- function _handleExistingItems(existingItemsResponse, templateDictionary, authentication, addTagQuery) {
747
- // if items are not found by type keyword search by tag
748
- var existingItemsByTag = [Promise.resolve(null)];
749
- /* istanbul ignore else */
750
- if (existingItemsResponse && Array.isArray(existingItemsResponse)) {
751
- existingItemsResponse.forEach(function (existingItem) {
752
- /* istanbul ignore else */
753
- if (Array.isArray(existingItem === null || existingItem === void 0 ? void 0 : existingItem.results)) {
754
- var result = void 0;
755
- var results = existingItem.results;
756
- if (results.length === 1) {
757
- result = results[0];
758
- }
759
- else if (results.length > 1) {
760
- result = results.reduce(function (a, b) {
761
- return a.created > b.created ? a : b;
762
- });
763
- }
764
- else {
765
- if (addTagQuery && existingItem.query) {
766
- var tagQuery = existingItem.query.replace("typekeywords", "tags");
767
- existingItemsByTag.push(_findExistingItem(tagQuery, authentication));
768
- }
769
- }
770
- if (result) {
771
- var sourceId = existingItem.query
772
- ? existingItem.query.match(/[0-9A-F]{32}/i)[0]
773
- : existingItem.sourceId;
774
- /* istanbul ignore else */
775
- if (sourceId) {
776
- _updateTemplateDictionaryById(templateDictionary, sourceId, result.id, result);
777
- }
778
- }
779
- }
780
- });
781
- }
782
- return existingItemsByTag;
783
- }
784
- function _updateTemplateDictionaryById(templateDictionary, sourceId, itemId, v) {
785
- templateDictionary[sourceId] = Object.assign(templateDictionary[sourceId] || {}, {
786
- def: Promise.resolve(common.generateEmptyCreationResponse(v.type, itemId)),
787
- itemId: itemId,
788
- name: v.name,
789
- title: v.title,
790
- url: v.url
791
- });
792
- }
793
- /**
794
- * Search items based on user query
795
- *
796
- * @param query Query string to use
797
- * @param authentication Credentials for the request
798
- * @return A promise that will resolve with an array of results
799
- * @protected
800
- */
801
- function _findExistingItemByKeyword(templates, templateDictionary, authentication) {
802
- var existingItemsDefs = [];
803
- templates.forEach(function (template) {
804
- var _a;
805
- if (template.item.type === "Group") {
806
- var userGroups = (_a = templateDictionary.user) === null || _a === void 0 ? void 0 : _a.groups;
807
- /* istanbul ignore else */
808
- if (Array.isArray(userGroups)) {
809
- existingItemsDefs.push(Promise.resolve({
810
- results: userGroups
811
- .filter(function (g) { return g.tags.indexOf("source-" + template.itemId) > -1; })
812
- .map(function (g) {
813
- g.type = "Group";
814
- return g;
815
- }),
816
- sourceId: template.itemId
817
- }));
818
- }
819
- }
820
- else {
821
- existingItemsDefs.push(_findExistingItem("typekeywords:source-" + template.itemId + " type:" + template.item.type + " owner:" + templateDictionary.user.username, authentication));
822
- }
823
- });
824
- return existingItemsDefs;
825
- }
826
- /**
827
- * Search items based on user query
828
- *
829
- * @param query Query string to use
830
- * @param authentication Credentials for the request
831
- * @return A promise that will resolve with an array of results
832
- * @protected
833
- */
834
- function _findExistingItem(query, authentication) {
835
- var searchOptions = {
836
- q: query,
837
- authentication: authentication,
838
- pagingParam: { start: 1, num: 100 }
839
- };
840
- return common.searchItems(searchOptions);
841
- }
842
- /**
843
- * Creates an item from a template once the item's dependencies have been created.
844
- *
845
- * @param template Template of item to deploy
846
- * @param resourceFilePaths URL, folder, and filename for each item resource/metadata/thumbnail
847
- * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
848
- * @param userSession Options for the request
849
- * @param itemProgressCallback Function for reporting progress updates from type-specific template handlers
850
- * @return A promise that will resolve with the id of the deployed item (which is simply returned if it's
851
- * already in the templates list
852
- * @protected
853
- */
854
- function _createItemFromTemplateWhenReady(template, resourceFilePaths, storageAuthentication, templateDictionary, destinationAuthentication, itemProgressCallback) {
855
- // ensure this is present
856
- template.dependencies = template.dependencies || [];
857
- // if there is no entry in the templateDictionary
858
- // or if we have a basic entry without the deferred request for its creation, add it
859
- if (!templateDictionary.hasOwnProperty(template.itemId) ||
860
- !common.getProp(templateDictionary[template.itemId], "def")) {
861
- var createResponse_1;
862
- var statusCode_1 = common.EItemProgressStatus.Unknown;
863
- var itemHandler_1;
864
- templateDictionary[template.itemId] =
865
- templateDictionary[template.itemId] || {};
866
- // Save the deferred for the use of items that depend on this item being created first
867
- templateDictionary[template.itemId].def = new Promise(function (resolve) {
868
- // Wait until all of the item's dependencies are deployed
869
- var _awaitDependencies = template.dependencies.reduce(function (acc, id) {
870
- var def = common.getProp(templateDictionary, id + ".def");
871
- // can't use maybePush as that clones the object, which does not work for Promises
872
- /* istanbul ignore else */
873
- if (def) {
874
- acc.push(def);
875
- }
876
- return acc;
877
- }, []);
878
- var syncViews = common.getProp(template, "properties.syncViews");
879
- var awaitDependencies = syncViews && syncViews.length > 0
880
- ? syncViews.reduce(function (acc, v) {
881
- var def = common.getProp(templateDictionary, v + ".def");
882
- /* istanbul ignore else */
883
- if (def) {
884
- acc.push(def);
885
- }
886
- return acc;
887
- }, _awaitDependencies)
888
- : _awaitDependencies;
889
- Promise.all(awaitDependencies)
890
- .then(function () {
891
- // Find the conversion handler for this item type
892
- var templateType = template.type;
893
- itemHandler_1 = moduleMap[templateType];
894
- if (!itemHandler_1 || itemHandler_1 === UNSUPPORTED$1) {
895
- if (itemHandler_1 === UNSUPPORTED$1) {
896
- statusCode_1 = common.EItemProgressStatus.Ignored;
897
- throw new Error();
898
- }
899
- else {
900
- statusCode_1 = common.EItemProgressStatus.Failed;
901
- throw new Error();
902
- }
903
- }
904
- // Get the item's thumbnail
905
- return common.getThumbnailFromStorageItem(storageAuthentication, resourceFilePaths);
906
- })
907
- .then(function (thumbnail) {
908
- template.item.thumbnail = thumbnail;
909
- // Delegate the creation of the item to the handler
910
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
911
- return itemHandler_1.createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback);
912
- })
913
- .then(function (response) {
914
- if (response.id === "") {
915
- statusCode_1 = common.EItemProgressStatus.Failed;
916
- throw new Error("handled"); // fails to create item
917
- }
918
- /* istanbul ignore else */
919
- createResponse_1 = response;
920
- if (createResponse_1.item.item.url) {
921
- common.setCreateProp(templateDictionary, template.itemId + ".url", createResponse_1.item.item.url);
922
- }
923
- // Copy resources, metadata, form
924
- return common.copyFilesFromStorageItem(storageAuthentication, resourceFilePaths, templateDictionary.folderId, createResponse_1.id, destinationAuthentication, createResponse_1.item);
925
- })
926
- .then(function () {
927
- resolve(createResponse_1);
928
- })
929
- .catch(function (error) {
930
- if (!error || error.message !== "handled") {
931
- itemProgressCallback(template.itemId, statusCode_1 === common.EItemProgressStatus.Unknown
932
- ? common.EItemProgressStatus.Failed
933
- : statusCode_1, 0);
934
- }
935
- // Item type not supported or fails to get item dependencies
936
- resolve(common.generateEmptyCreationResponse(template.type));
937
- });
938
- });
939
- }
940
- return templateDictionary[template.itemId].def;
941
- }
942
- /**
943
- * Accumulates the estimated deployment cost of a set of templates.
944
- *
945
- * @param templates Templates to examine
946
- * @return Sum of estimated deployment costs
947
- * @protected
948
- */
949
- function _estimateDeploymentCost(templates) {
950
- return templates.reduce(function (accumulatedEstimatedCost, template) {
951
- return (accumulatedEstimatedCost + (template.estimatedDeploymentCostFactor || 1));
952
- }, 0);
953
- }
954
- // TODO: Return a Promise vs array of promises
955
- function _getGroupUpdates(template, authentication, templateDictionary) {
956
- var groups = template.groups || [];
957
- return groups.map(function (sourceGroupId) {
958
- return common.shareItem(templateDictionary[sourceGroupId].itemId, template.itemId, authentication);
959
- });
960
- }
1001
+ /** @license
1002
+ * Copyright 2020 Esri
1003
+ *
1004
+ * Licensed under the Apache License, Version 2.0 (the "License");
1005
+ * you may not use this file except in compliance with the License.
1006
+ * You may obtain a copy of the License at
1007
+ *
1008
+ * http://www.apache.org/licenses/LICENSE-2.0
1009
+ *
1010
+ * Unless required by applicable law or agreed to in writing, software
1011
+ * distributed under the License is distributed on an "AS IS" BASIS,
1012
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1013
+ * See the License for the specific language governing permissions and
1014
+ * limitations under the License.
1015
+ */
1016
+ /**
1017
+ * Given the created templates
1018
+ *
1019
+ * @param templates
1020
+ * @param templateDictionary
1021
+ * @param authentication
1022
+ */
1023
+ function shareTemplatesToGroups(templates, templateDictionary, authentication) {
1024
+ // Filter to entries with groups to share to
1025
+ const templatesWithGroups = templates.filter(e => {
1026
+ return e.groups && e.groups.length > 0;
1027
+ });
1028
+ // fire off all the promises
1029
+ return Promise.all(templatesWithGroups.map(tmpl => {
1030
+ const groupIds = tmpl.groups.reduce((acc, sourceGroupId) => {
1031
+ return hubCommon.maybePush(common.getProp(templateDictionary, `${sourceGroupId}.itemId`), acc);
1032
+ }, []);
1033
+ // need to pass the tracking owner when sharing to tracking group
1034
+ if (common.isTrackingViewTemplate(tmpl) && !common.getProp(templateDictionary, "locationTracking.userIsOwner")) {
1035
+ const trackingGroupId = common.getProp(tmpl, "item.properties.trackViewGroup");
1036
+ const owner = common.getProp(templateDictionary, "locationTracking.owner");
1037
+ /* istanbul ignore else */
1038
+ if (trackingGroupId && owner) {
1039
+ const trackerGroupIds = groupIds.filter(id => {
1040
+ return id === common.replaceInTemplate(trackingGroupId, templateDictionary);
1041
+ });
1042
+ if (trackerGroupIds.length !== groupIds.length) {
1043
+ const nonTrackerGroupIds = groupIds.filter(id => id !== trackingGroupId);
1044
+ return Promise.all([
1045
+ common.shareItemToGroups(trackerGroupIds, tmpl.itemId, authentication, owner),
1046
+ common.shareItemToGroups(nonTrackerGroupIds, tmpl.itemId, authentication)
1047
+ ]);
1048
+ }
1049
+ else {
1050
+ return common.shareItemToGroups(groupIds, tmpl.itemId, authentication, owner);
1051
+ }
1052
+ }
1053
+ }
1054
+ else {
1055
+ return common.shareItemToGroups(groupIds, tmpl.itemId, authentication);
1056
+ }
1057
+ }));
1058
+ }
961
1059
 
962
- /** @license
963
- * Copyright 2020 Esri
964
- *
965
- * Licensed under the Apache License, Version 2.0 (the "License");
966
- * you may not use this file except in compliance with the License.
967
- * You may obtain a copy of the License at
968
- *
969
- * http://www.apache.org/licenses/LICENSE-2.0
970
- *
971
- * Unless required by applicable law or agreed to in writing, software
972
- * distributed under the License is distributed on an "AS IS" BASIS,
973
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
974
- * See the License for the specific language governing permissions and
975
- * limitations under the License.
976
- */
977
- /**
978
- * Given the created templates
979
- *
980
- * @param templates
981
- * @param templateDictionary
982
- * @param authentication
983
- */
984
- function shareTemplatesToGroups(templates, templateDictionary, authentication) {
985
- // Filter to entries with groups to share to
986
- var templatesWithGroups = templates.filter(function (e) {
987
- return e.groups && e.groups.length > 0;
988
- });
989
- // fire off all the promises
990
- return Promise.all(templatesWithGroups.map(function (tmpl) {
991
- var groupIds = tmpl.groups.reduce(function (acc, sourceGroupId) {
992
- return hubCommon.maybePush(common.getProp(templateDictionary, sourceGroupId + ".itemId"), acc);
993
- }, []);
994
- return common.shareItemToGroups(groupIds, tmpl.itemId, authentication);
995
- }));
996
- }
1060
+ /** @license
1061
+ * Copyright 2020 Esri
1062
+ *
1063
+ * Licensed under the Apache License, Version 2.0 (the "License");
1064
+ * you may not use this file except in compliance with the License.
1065
+ * You may obtain a copy of the License at
1066
+ *
1067
+ * http://www.apache.org/licenses/LICENSE-2.0
1068
+ *
1069
+ * Unless required by applicable law or agreed to in writing, software
1070
+ * distributed under the License is distributed on an "AS IS" BASIS,
1071
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1072
+ * See the License for the specific language governing permissions and
1073
+ * limitations under the License.
1074
+ */
1075
+ /**
1076
+ * Delegate post-processing to the type specific
1077
+ * processors. This allows each type to have fine-grained
1078
+ * control over what they do. Common post-processing is
1079
+ * exposed as functions that can be imported
1080
+ *
1081
+ * @param deployedSolutionId
1082
+ * @param templates
1083
+ * @param clonedSolutions
1084
+ * @param authentication
1085
+ * @param templateDictionary
1086
+ */
1087
+ function postProcess(deployedSolutionId, templates, clonedSolutions, authentication, templateDictionary) {
1088
+ // connect the solution with its items; groups cannot be connected
1089
+ const relationshipPromises = clonedSolutions
1090
+ .filter(entry => entry.type !== "Group")
1091
+ .map(entry => portal.addItemRelationship({
1092
+ originItemId: deployedSolutionId,
1093
+ destinationItemId: entry.id,
1094
+ relationshipType: "Solution2Item",
1095
+ authentication: authentication
1096
+ }) // TODO: remove `as any`, which is here until arcgis-rest-js' ItemRelationshipType defn catches up
1097
+ );
1098
+ // delegate sharing to groups
1099
+ const sharePromises = shareTemplatesToGroups(templates, templateDictionary, authentication);
1100
+ // what needs post processing?
1101
+ const itemsToProcess = clonedSolutions.filter(entry => entry.postProcess);
1102
+ // map over these items
1103
+ const postProcessPromises = itemsToProcess.reduce((acc, entry) => {
1104
+ const itemHandler = moduleMap[entry.type];
1105
+ // only delegate if the handler has a postProcess method
1106
+ if (itemHandler && itemHandler.postProcess) {
1107
+ acc.push(itemHandler.postProcess(entry.id, entry.type, clonedSolutions, common.getTemplateById(templates, entry.id), templates, templateDictionary, authentication));
1108
+ }
1109
+ return acc;
1110
+ }, []);
1111
+ return Promise.all([sharePromises].concat(postProcessPromises, relationshipPromises));
1112
+ }
997
1113
 
998
- /**
999
- * Delegate post-processing to the type specific
1000
- * processors. This allows each type to have fine-grained
1001
- * control over what they do. Common post-processing is
1002
- * exposed as functions that can be imported
1003
- *
1004
- * @param deployedSolutionId
1005
- * @param templates
1006
- * @param clonedSolutions
1007
- * @param authentication
1008
- * @param templateDictionary
1009
- */
1010
- function postProcess(deployedSolutionId, templates, clonedSolutions, authentication, templateDictionary) {
1011
- // connect the solution with its items; groups cannot be connected
1012
- var relationshipPromises = clonedSolutions
1013
- .filter(function (entry) { return entry.type !== "Group"; })
1014
- .map(function (entry) {
1015
- return arcgisRestPortal.addItemRelationship({
1016
- originItemId: deployedSolutionId,
1017
- destinationItemId: entry.id,
1018
- relationshipType: "Solution2Item",
1019
- authentication: authentication
1020
- });
1021
- } // TODO: remove `as any`, which is here until arcgis-rest-js' ItemRelationshipType defn catches up
1022
- );
1023
- // delegate sharing to groups
1024
- var sharePromises = shareTemplatesToGroups(templates, templateDictionary, authentication);
1025
- // what needs post processing?
1026
- var itemsToProcess = clonedSolutions.filter(function (entry) { return entry.postProcess; });
1027
- // map over these items
1028
- var postProcessPromises = itemsToProcess.reduce(function (acc, entry) {
1029
- var itemHandler = moduleMap[entry.type];
1030
- // only delegate if the handler has a postProcess method
1031
- if (itemHandler && itemHandler.postProcess) {
1032
- acc.push(itemHandler.postProcess(entry.id, entry.type, clonedSolutions, common.getTemplateById(templates, entry.id), templates, templateDictionary, authentication));
1033
- }
1034
- return acc;
1035
- }, []);
1036
- return Promise.all(__spread(postProcessPromises, [
1037
- sharePromises
1038
- ], relationshipPromises));
1039
- }
1114
+ /**
1115
+ * Sorts a list of templates in place to match a provided sort-order list.
1116
+ *
1117
+ * @param templates List of templates in a Solution
1118
+ * @param sortOrderIds List of template ids in the desired sort order
1119
+ */
1120
+ function sortTemplates(templates, sortOrderIds) {
1121
+ templates.sort((template1, template2) => sortOrderIds.indexOf(template1.itemId) -
1122
+ sortOrderIds.indexOf(template2.itemId));
1123
+ }
1040
1124
 
1041
- /**
1042
- * Sorts a list of templates in place to match a provided sort-order list.
1043
- *
1044
- * @param templates List of templates in a Solution
1045
- * @param sortOrderIds List of template ids in the desired sort order
1046
- */
1047
- function sortTemplates(templates, sortOrderIds) {
1048
- templates.sort(function (template1, template2) {
1049
- return sortOrderIds.indexOf(template1.itemId) -
1050
- sortOrderIds.indexOf(template2.itemId);
1051
- });
1052
- }
1125
+ /** @license
1126
+ * Copyright 2018 Esri
1127
+ *
1128
+ * Licensed under the Apache License, Version 2.0 (the "License");
1129
+ * you may not use this file except in compliance with the License.
1130
+ * You may obtain a copy of the License at
1131
+ *
1132
+ * http://www.apache.org/licenses/LICENSE-2.0
1133
+ *
1134
+ * Unless required by applicable law or agreed to in writing, software
1135
+ * distributed under the License is distributed on an "AS IS" BASIS,
1136
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1137
+ * See the License for the specific language governing permissions and
1138
+ * limitations under the License.
1139
+ */
1140
+ // NOTE: Moved to separate file to allow stubbing in main deploySolution tests
1141
+ function deploySolutionFromTemplate(templateSolutionId, solutionTemplateBase, solutionTemplateData, authentication, options) {
1142
+ options.storageVersion = common.extractSolutionVersion(solutionTemplateData);
1143
+ return new Promise((resolve, reject) => {
1144
+ // It is possible to provide a separate authentication for the source
1145
+ const storageAuthentication = options.storageAuthentication
1146
+ ? options.storageAuthentication
1147
+ : authentication;
1148
+ // Replacement dictionary and high-level deployment ids for cleanup
1149
+ // TODO: Extract all templateDictionary prep into a separate function
1150
+ const templateDictionary = options.templateDictionary ?? {};
1151
+ let deployedFolderId;
1152
+ let deployedSolutionId;
1153
+ _applySourceToDeployOptions(options, solutionTemplateBase, templateDictionary, authentication);
1154
+ if (options.additionalTypeKeywords) {
1155
+ solutionTemplateBase.typeKeywords = [].concat(solutionTemplateBase.typeKeywords, options.additionalTypeKeywords);
1156
+ }
1157
+ // Get the thumbnail file
1158
+ let thumbFilename = "thumbnail";
1159
+ let thumbDef = Promise.resolve(null);
1160
+ if (!options.thumbnail && options.thumbnailurl) {
1161
+ // Figure out the thumbnail's filename
1162
+ thumbFilename =
1163
+ common.getFilenameFromUrl(options.thumbnailurl) || thumbFilename;
1164
+ const thumbnailurl = common.appendQueryParam(options.thumbnailurl, "w=400");
1165
+ delete options.thumbnailurl;
1166
+ // Fetch the thumbnail
1167
+ thumbDef = common.getBlobAsFile(thumbnailurl, thumbFilename, storageAuthentication, [400]);
1168
+ }
1169
+ _replaceParamVariables(solutionTemplateData, templateDictionary);
1170
+ // Get information about deployment environment
1171
+ Promise.all([
1172
+ common.getPortal("", authentication),
1173
+ common.getUser(authentication),
1174
+ common.getFoldersAndGroups(authentication),
1175
+ thumbDef
1176
+ ])
1177
+ .then(responses => {
1178
+ const [portalResponse, userResponse, foldersAndGroupsResponse, thumbnailFile] = responses;
1179
+ if (!options.thumbnail && thumbnailFile) {
1180
+ options.thumbnail = thumbnailFile;
1181
+ }
1182
+ // update template items with source-itemId type keyword
1183
+ solutionTemplateData.templates = solutionTemplateData.templates.map((template) => {
1184
+ const sourceId = "source-" + template.itemId;
1185
+ /* istanbul ignore else */
1186
+ if (template.item) {
1187
+ /* istanbul ignore else */
1188
+ if (template.item.typeKeywords) {
1189
+ template.item.typeKeywords.push(sourceId);
1190
+ }
1191
+ /* istanbul ignore else */
1192
+ if (template.item.tags &&
1193
+ common.getProp(template, "item.type") === "Group") {
1194
+ template.item.tags.push(sourceId);
1195
+ }
1196
+ }
1197
+ return template;
1198
+ });
1199
+ templateDictionary.isPortal = portalResponse.isPortal;
1200
+ templateDictionary.organization = Object.assign(templateDictionary.organization || {}, portalResponse);
1201
+ // TODO: Add more computed properties here
1202
+ // portal: portalResponse
1203
+ // orgextent as bbox for assignment onto items
1204
+ // more info in #266 https://github.com/Esri/solution.js/issues/266
1205
+ templateDictionary.portalBaseUrl = _getPortalBaseUrl(portalResponse, authentication);
1206
+ templateDictionary.user = userResponse;
1207
+ templateDictionary.user.folders = foldersAndGroupsResponse.folders;
1208
+ templateDictionary.user.groups = foldersAndGroupsResponse.groups.filter((group) => group.owner === templateDictionary.user.username);
1209
+ // if we have tracking views and the user is not admin or the org doesn't support tracking an error is thrown
1210
+ common.setLocationTrackingEnabled(portalResponse, userResponse, templateDictionary, solutionTemplateData.templates);
1211
+ const trackingOwnerPromise = common.getTackingServiceOwner(templateDictionary, authentication);
1212
+ // Create a folder to hold the deployed solution. We use the solution name, appending a sequential
1213
+ // suffix if the folder exists, e.g.,
1214
+ // * Manage Right of Way Activities
1215
+ // * Manage Right of Way Activities 1
1216
+ // * Manage Right of Way Activities 2
1217
+ const folderPromise = common.createUniqueFolder(solutionTemplateBase.title, templateDictionary, authentication);
1218
+ // Apply the portal extents to the solution
1219
+ const portalExtent = portalResponse.defaultExtent;
1220
+ const extentsPromise = common.convertExtentWithFallback(portalExtent, undefined, { wkid: 4326 }, portalResponse.helperServices.geometry.url, authentication);
1221
+ // Await completion of async actions: folder creation & extents conversion
1222
+ return Promise.all([folderPromise, extentsPromise, trackingOwnerPromise]);
1223
+ })
1224
+ .then(responses => {
1225
+ const [folderResponse, wgs84Extent, trackingOwnerResponse] = responses;
1226
+ deployedFolderId = folderResponse.folder.id;
1227
+ templateDictionary.folderId = deployedFolderId;
1228
+ templateDictionary.solutionItemExtent =
1229
+ wgs84Extent.xmin +
1230
+ "," +
1231
+ wgs84Extent.ymin +
1232
+ "," +
1233
+ wgs84Extent.xmax +
1234
+ "," +
1235
+ wgs84Extent.ymax;
1236
+ // Hub Solutions depend on organization defaultExtentBBox as a nested array not a string
1237
+ templateDictionary.organization.defaultExtentBBox = [
1238
+ [wgs84Extent.xmin, wgs84Extent.ymin],
1239
+ [wgs84Extent.xmax, wgs84Extent.ymax]
1240
+ ];
1241
+ // update templateDictionary to indicate if the user owns the tracking service
1242
+ // this will affect how we handle group sharing
1243
+ /* istanbul ignore else */
1244
+ if (templateDictionary.locationTrackingEnabled) {
1245
+ common.setCreateProp(templateDictionary, "locationTracking.userIsOwner", trackingOwnerResponse);
1246
+ }
1247
+ // Create a deployed Solution item
1248
+ const createSolutionItemBase = {
1249
+ ...common.sanitizeJSONAndReportChanges(solutionTemplateBase),
1250
+ type: "Solution",
1251
+ typeKeywords: ["Solution"]
1252
+ };
1253
+ if (options.additionalTypeKeywords) {
1254
+ createSolutionItemBase.typeKeywords = ["Solution"].concat(options.additionalTypeKeywords);
1255
+ }
1256
+ // Create deployed solution item
1257
+ createSolutionItemBase.thumbnail = options.thumbnail;
1258
+ return common.createItemWithData(createSolutionItemBase, {}, authentication, deployedFolderId);
1259
+ })
1260
+ .then(createSolutionResponse => {
1261
+ deployedSolutionId = createSolutionResponse.id;
1262
+ // Protect the solution item
1263
+ const protectOptions = {
1264
+ id: deployedSolutionId,
1265
+ authentication
1266
+ };
1267
+ return portal.protectItem(protectOptions);
1268
+ })
1269
+ .then(() => {
1270
+ // TODO: Attach the whole solution model so we can
1271
+ // have stuff like `{{solution.item.title}}
1272
+ templateDictionary.solutionItemId = deployedSolutionId;
1273
+ solutionTemplateBase.id = deployedSolutionId;
1274
+ solutionTemplateBase.tryitUrl = _checkedReplaceAll(solutionTemplateBase.tryitUrl, templateSolutionId, deployedSolutionId);
1275
+ solutionTemplateBase.url = _checkedReplaceAll(solutionTemplateBase.url, templateSolutionId, deployedSolutionId);
1276
+ // Handle the contained item templates
1277
+ return deploySolutionItems(storageAuthentication.portal, templateSolutionId, solutionTemplateData.templates, storageAuthentication, templateDictionary, deployedSolutionId, authentication, options);
1278
+ })
1279
+ .then((clonedSolutionsResponse) => {
1280
+ solutionTemplateData.templates = solutionTemplateData.templates.map((itemTemplate) => {
1281
+ // Update ids present in template dictionary
1282
+ itemTemplate.itemId = common.getProp(templateDictionary, `${itemTemplate.itemId}.itemId`);
1283
+ // Update the dependencies hash to point to the new item ids
1284
+ itemTemplate.dependencies = itemTemplate.dependencies.map((id) => hubCommon.getWithDefault(templateDictionary, `${id}.itemId`, id));
1285
+ return itemTemplate;
1286
+ });
1287
+ // Sort the templates into build order, which is provided by clonedSolutionsResponse
1288
+ sortTemplates(solutionTemplateData.templates, clonedSolutionsResponse.map(response => response.id));
1289
+ // Wrap up with post-processing, in which we deal with groups and cycle remnants
1290
+ return postProcess(deployedSolutionId, solutionTemplateData.templates, clonedSolutionsResponse, authentication, templateDictionary);
1291
+ })
1292
+ .then(() => {
1293
+ // Update solution item using internal representation & and the updated data JSON
1294
+ solutionTemplateBase.typeKeywords = [].concat(solutionTemplateBase.typeKeywords, ["Deployed"]);
1295
+ const iTemplateKeyword = solutionTemplateBase.typeKeywords.indexOf("Template");
1296
+ /* istanbul ignore else */
1297
+ if (iTemplateKeyword >= 0) {
1298
+ solutionTemplateBase.typeKeywords.splice(iTemplateKeyword, 1);
1299
+ }
1300
+ solutionTemplateData.templates = solutionTemplateData.templates.map((itemTemplate) => _purgeTemplateProperties(itemTemplate));
1301
+ solutionTemplateData.templates = _updateGroupReferences(solutionTemplateData.templates, templateDictionary);
1302
+ // Update solution items data using template dictionary, and then update the
1303
+ // itemId & dependencies in each item template
1304
+ solutionTemplateBase.data = common.replaceInTemplate(solutionTemplateData, templateDictionary);
1305
+ // Write any user defined params to the solution
1306
+ /* istanbul ignore else */
1307
+ if (templateDictionary.params) {
1308
+ solutionTemplateBase.data.params = templateDictionary.params;
1309
+ }
1310
+ return common.updateItem(solutionTemplateBase, authentication, deployedFolderId);
1311
+ })
1312
+ .then(() => resolve(solutionTemplateBase.id), reject);
1313
+ });
1314
+ }
1315
+ /**
1316
+ * Update the deployOptions with the group properties
1317
+ *
1318
+ * @param deployOptions
1319
+ * @param sourceInfo
1320
+ * @param authentication
1321
+ * @param isGroup Boolean to indicate if the files are associated with a group or item
1322
+ * @internal
1323
+ */
1324
+ function _applySourceToDeployOptions(deployOptions, solutionTemplateBase, templateDictionary, authentication) {
1325
+ // Deploy a solution from the template's contents,
1326
+ // using the template's information as defaults for the deployed solution item
1327
+ ["title", "snippet", "description", "tags"].forEach(prop => {
1328
+ deployOptions[prop] = deployOptions[prop] ?? solutionTemplateBase[prop];
1329
+ if (deployOptions[prop]) {
1330
+ solutionTemplateBase[prop] = deployOptions[prop];
1331
+ // carry these options forward on the templateDict
1332
+ templateDictionary[prop] = deployOptions[prop];
1333
+ }
1334
+ });
1335
+ if (!deployOptions.thumbnailurl && solutionTemplateBase.thumbnail) {
1336
+ // Get the full path to the thumbnail
1337
+ deployOptions.thumbnailurl = common.generateSourceThumbnailUrl(authentication.portal, solutionTemplateBase.id, solutionTemplateBase.thumbnail);
1338
+ delete solutionTemplateBase.thumbnail;
1339
+ }
1340
+ return deployOptions;
1341
+ }
1342
+ function _replaceParamVariables(solutionTemplateData, templateDictionary) {
1343
+ // a custom params object can be passed in with the options to deploy a solution
1344
+ // in most cases we can defer to the item type handlers to use these values
1345
+ // for variable replacement
1346
+ // for spatial reference specifically we need to replace up front so the default extent
1347
+ // logic can execute as expected
1348
+ solutionTemplateData.templates = solutionTemplateData.templates.map((template) => {
1349
+ // can't do this as it causes other values that don't exist in the dict yet to revert to defaults they may have defined
1350
+ // return common.replaceInTemplate(template, templateDictionary);
1351
+ /* istanbul ignore else */
1352
+ if (template.type === "Feature Service") {
1353
+ const paramsLookup = "params.";
1354
+ const wkidItemPath = "item.spatialReference.wkid";
1355
+ template = _updateProp(template, wkidItemPath, paramsLookup, templateDictionary);
1356
+ const wkidServicePath = "properties.service.spatialReference.wkid";
1357
+ template = _updateProp(template, wkidServicePath, paramsLookup, templateDictionary);
1358
+ }
1359
+ return template;
1360
+ });
1361
+ }
1362
+ function _updateProp(template, path, lookup, templateDictionary) {
1363
+ const wkid = common.getProp(template, path);
1364
+ /* istanbul ignore else */
1365
+ if (wkid && typeof wkid === "string" && wkid.indexOf(lookup) > -1) {
1366
+ common.setProp(template, path, common.replaceInTemplate(wkid, templateDictionary));
1367
+ }
1368
+ return template;
1369
+ }
1370
+ function _checkedReplaceAll(template, oldValue, newValue) {
1371
+ let newTemplate;
1372
+ if (template && template.indexOf(oldValue) > -1) {
1373
+ const re = new RegExp(oldValue, "g");
1374
+ newTemplate = template.replace(re, newValue);
1375
+ }
1376
+ else {
1377
+ newTemplate = template;
1378
+ }
1379
+ return newTemplate;
1380
+ }
1381
+ function _getPortalBaseUrl(portalResponse, authentication) {
1382
+ // As of Spring 2020, only HTTPS (see
1383
+ // https://www.esri.com/arcgis-blog/products/product/administration/2019-arcgis-transport-security-improvements/)
1384
+ const scheme = "https"; // portalResponse.allSSL ? "https" : "http";
1385
+ const urlKey = common.getProp(portalResponse, "urlKey");
1386
+ const customBaseUrl = common.getProp(portalResponse, "customBaseUrl");
1387
+ const enterpriseBaseUrl = common.getProp(portalResponse, "portalHostname");
1388
+ return urlKey && customBaseUrl
1389
+ ? `${scheme}://${urlKey}.${customBaseUrl}`
1390
+ : enterpriseBaseUrl
1391
+ ? `${scheme}://${enterpriseBaseUrl}`
1392
+ : authentication.portal.replace("/sharing/rest", "");
1393
+ }
1394
+ function _updateGroupReferences(itemTemplates, templateDictionary) {
1395
+ const groupIds = itemTemplates.reduce((result, t) => {
1396
+ if (t.type === "Group") {
1397
+ result.push(t.itemId);
1398
+ }
1399
+ return result;
1400
+ }, []);
1401
+ Object.keys(templateDictionary).forEach(k => {
1402
+ const newId = templateDictionary[k].itemId;
1403
+ if (groupIds.indexOf(newId) > -1) {
1404
+ itemTemplates.forEach(t => {
1405
+ t.groups = t.groups.map((id) => (id === k ? newId : id));
1406
+ });
1407
+ }
1408
+ });
1409
+ return itemTemplates;
1410
+ }
1411
+ function _purgeTemplateProperties(itemTemplate) {
1412
+ const retainProps = ["itemId", "type", "dependencies", "groups"];
1413
+ const deleteProps = Object.keys(itemTemplate).filter(k => retainProps.indexOf(k) < 0);
1414
+ common.deleteProps(itemTemplate, deleteProps);
1415
+ return itemTemplate;
1416
+ }
1053
1417
 
1054
- /** @license
1055
- * Copyright 2018 Esri
1056
- *
1057
- * Licensed under the Apache License, Version 2.0 (the "License");
1058
- * you may not use this file except in compliance with the License.
1059
- * You may obtain a copy of the License at
1060
- *
1061
- * http://www.apache.org/licenses/LICENSE-2.0
1062
- *
1063
- * Unless required by applicable law or agreed to in writing, software
1064
- * distributed under the License is distributed on an "AS IS" BASIS,
1065
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1066
- * See the License for the specific language governing permissions and
1067
- * limitations under the License.
1068
- */
1069
- // NOTE: Moved to separate file to allow stubbing in main deploySolution tests
1070
- function deploySolutionFromTemplate(templateSolutionId, solutionTemplateBase, solutionTemplateData, authentication, options) {
1071
- options.storageVersion = common.extractSolutionVersion(solutionTemplateData);
1072
- return new Promise(function (resolve, reject) {
1073
- var _a;
1074
- // It is possible to provide a separate authentication for the source
1075
- var storageAuthentication = options.storageAuthentication
1076
- ? options.storageAuthentication
1077
- : authentication;
1078
- // Replacement dictionary and high-level deployment ids for cleanup
1079
- // TODO: Extract all templateDictionary prep into a separate function
1080
- var templateDictionary = (_a = options.templateDictionary) !== null && _a !== void 0 ? _a : {};
1081
- var deployedFolderId;
1082
- var deployedSolutionId;
1083
- _applySourceToDeployOptions(options, solutionTemplateBase, templateDictionary, authentication);
1084
- if (options.additionalTypeKeywords) {
1085
- solutionTemplateBase.typeKeywords = [].concat(solutionTemplateBase.typeKeywords, options.additionalTypeKeywords);
1086
- }
1087
- // Get the thumbnail file
1088
- var thumbFilename = "thumbnail";
1089
- var thumbDef = Promise.resolve(null);
1090
- if (!options.thumbnail && options.thumbnailurl) {
1091
- // Figure out the thumbnail's filename
1092
- thumbFilename =
1093
- common.getFilenameFromUrl(options.thumbnailurl) || thumbFilename;
1094
- var thumbnailurl = common.appendQueryParam(options.thumbnailurl, "w=400");
1095
- delete options.thumbnailurl;
1096
- // Fetch the thumbnail
1097
- thumbDef = common.getBlobAsFile(thumbnailurl, thumbFilename, storageAuthentication, [400]);
1098
- }
1099
- _replaceParamVariables(solutionTemplateData, templateDictionary);
1100
- // Get information about deployment environment
1101
- Promise.all([
1102
- common.getPortal("", authentication),
1103
- common.getUser(authentication),
1104
- common.getFoldersAndGroups(authentication),
1105
- thumbDef
1106
- ])
1107
- .then(function (responses) {
1108
- var _a = __read(responses, 4), portalResponse = _a[0], userResponse = _a[1], foldersAndGroupsResponse = _a[2], thumbnailFile = _a[3];
1109
- if (!options.thumbnail && thumbnailFile) {
1110
- options.thumbnail = thumbnailFile;
1111
- }
1112
- // update template items with source-itemId type keyword
1113
- solutionTemplateData.templates = solutionTemplateData.templates.map(function (template) {
1114
- var sourceId = "source-" + template.itemId;
1115
- /* istanbul ignore else */
1116
- if (template.item) {
1117
- /* istanbul ignore else */
1118
- if (template.item.typeKeywords) {
1119
- template.item.typeKeywords.push(sourceId);
1120
- }
1121
- /* istanbul ignore else */
1122
- if (template.item.tags &&
1123
- common.getProp(template, "item.type") === "Group") {
1124
- template.item.tags.push(sourceId);
1125
- }
1126
- }
1127
- return template;
1128
- });
1129
- templateDictionary.isPortal = portalResponse.isPortal;
1130
- templateDictionary.organization = Object.assign(templateDictionary.organization || {}, portalResponse);
1131
- // TODO: Add more computed properties here
1132
- // portal: portalResponse
1133
- // orgextent as bbox for assignment onto items
1134
- // more info in #266 https://github.com/Esri/solution.js/issues/266
1135
- templateDictionary.portalBaseUrl = _getPortalBaseUrl(portalResponse, authentication);
1136
- templateDictionary.user = userResponse;
1137
- templateDictionary.user.folders = foldersAndGroupsResponse.folders;
1138
- templateDictionary.user.groups = foldersAndGroupsResponse.groups.filter(function (group) {
1139
- return group.owner === templateDictionary.user.username;
1140
- });
1141
- // Create a folder to hold the deployed solution. We use the solution name, appending a sequential
1142
- // suffix if the folder exists, e.g.,
1143
- // * Manage Right of Way Activities
1144
- // * Manage Right of Way Activities 1
1145
- // * Manage Right of Way Activities 2
1146
- var folderPromise = common.createUniqueFolder(solutionTemplateBase.title, templateDictionary, authentication);
1147
- // Apply the portal extents to the solution
1148
- var portalExtent = portalResponse.defaultExtent;
1149
- var extentsPromise = common.convertExtentWithFallback(portalExtent, undefined, { wkid: 4326 }, portalResponse.helperServices.geometry.url, authentication);
1150
- // Await completion of async actions: folder creation & extents conversion
1151
- return Promise.all([folderPromise, extentsPromise]);
1152
- })
1153
- .then(function (responses) {
1154
- var _a = __read(responses, 2), folderResponse = _a[0], wgs84Extent = _a[1];
1155
- deployedFolderId = folderResponse.folder.id;
1156
- templateDictionary.folderId = deployedFolderId;
1157
- templateDictionary.solutionItemExtent =
1158
- wgs84Extent.xmin +
1159
- "," +
1160
- wgs84Extent.ymin +
1161
- "," +
1162
- wgs84Extent.xmax +
1163
- "," +
1164
- wgs84Extent.ymax;
1165
- // Hub Solutions depend on organization defaultExtentBBox as a nested array not a string
1166
- templateDictionary.organization.defaultExtentBBox = [
1167
- [wgs84Extent.xmin, wgs84Extent.ymin],
1168
- [wgs84Extent.xmax, wgs84Extent.ymax]
1169
- ];
1170
- // Create a deployed Solution item
1171
- var createSolutionItemBase = __assign(__assign({}, common.sanitizeJSONAndReportChanges(solutionTemplateBase)), { type: "Solution", typeKeywords: ["Solution"] });
1172
- if (options.additionalTypeKeywords) {
1173
- createSolutionItemBase.typeKeywords = ["Solution"].concat(options.additionalTypeKeywords);
1174
- }
1175
- // Create deployed solution item
1176
- createSolutionItemBase.thumbnail = options.thumbnail;
1177
- return common.createItemWithData(createSolutionItemBase, {}, authentication, deployedFolderId);
1178
- })
1179
- .then(function (createSolutionResponse) {
1180
- deployedSolutionId = createSolutionResponse.id;
1181
- // TODO: Attach the whole solution model so we can
1182
- // have stuff like `{{solution.item.title}}
1183
- templateDictionary.solutionItemId = deployedSolutionId;
1184
- solutionTemplateBase.id = deployedSolutionId;
1185
- solutionTemplateBase.tryitUrl = _checkedReplaceAll(solutionTemplateBase.tryitUrl, templateSolutionId, deployedSolutionId);
1186
- solutionTemplateBase.url = _checkedReplaceAll(solutionTemplateBase.url, templateSolutionId, deployedSolutionId);
1187
- // Handle the contained item templates
1188
- return deploySolutionItems(storageAuthentication.portal, templateSolutionId, solutionTemplateData.templates, storageAuthentication, templateDictionary, authentication, options);
1189
- })
1190
- .then(function (clonedSolutionsResponse) {
1191
- solutionTemplateData.templates = solutionTemplateData.templates.map(function (itemTemplate) {
1192
- // Update ids present in template dictionary
1193
- itemTemplate.itemId = common.getProp(templateDictionary, itemTemplate.itemId + ".itemId");
1194
- // Update the dependencies hash to point to the new item ids
1195
- itemTemplate.dependencies = itemTemplate.dependencies.map(function (id) {
1196
- return hubCommon.getWithDefault(templateDictionary, id + ".itemId", id);
1197
- });
1198
- return itemTemplate;
1199
- });
1200
- // Sort the templates into build order, which is provided by clonedSolutionsResponse
1201
- sortTemplates(solutionTemplateData.templates, clonedSolutionsResponse.map(function (response) { return response.id; }));
1202
- // Wrap up with post-processing, in which we deal with groups and cycle remnants
1203
- return postProcess(deployedSolutionId, solutionTemplateData.templates, clonedSolutionsResponse, authentication, templateDictionary);
1204
- })
1205
- .then(function () {
1206
- // Update solution item using internal representation & and the updated data JSON
1207
- solutionTemplateBase.typeKeywords = [].concat(solutionTemplateBase.typeKeywords, ["Deployed"]);
1208
- var iTemplateKeyword = solutionTemplateBase.typeKeywords.indexOf("Template");
1209
- /* istanbul ignore else */
1210
- if (iTemplateKeyword >= 0) {
1211
- solutionTemplateBase.typeKeywords.splice(iTemplateKeyword, 1);
1212
- }
1213
- solutionTemplateData.templates = solutionTemplateData.templates.map(function (itemTemplate) {
1214
- return _purgeTemplateProperties(itemTemplate);
1215
- });
1216
- solutionTemplateData.templates = _updateGroupReferences(solutionTemplateData.templates, templateDictionary);
1217
- // Update solution items data using template dictionary, and then update the
1218
- // itemId & dependencies in each item template
1219
- solutionTemplateBase.data = common.replaceInTemplate(solutionTemplateData, templateDictionary);
1220
- // Write any user defined params to the solution
1221
- /* istanbul ignore else */
1222
- if (templateDictionary.params) {
1223
- solutionTemplateBase.data.params = templateDictionary.params;
1224
- }
1225
- return common.updateItem(solutionTemplateBase, authentication, deployedFolderId);
1226
- })
1227
- .then(function () { return resolve(solutionTemplateBase.id); }, function (error) {
1228
- // Cleanup solution folder and deployed solution item
1229
- var cleanupPromises = [];
1230
- if (deployedFolderId) {
1231
- cleanupPromises.push(common.removeFolder(deployedFolderId, authentication));
1232
- }
1233
- if (deployedSolutionId) {
1234
- cleanupPromises.push(common.removeItem(deployedSolutionId, authentication));
1235
- }
1236
- Promise.all(cleanupPromises).then(function () { return reject(error); }, function () { return reject(error); });
1237
- });
1238
- });
1239
- }
1240
- /**
1241
- * Update the deployOptions with the group properties
1242
- *
1243
- * @param deployOptions
1244
- * @param sourceInfo
1245
- * @param authentication
1246
- * @param isGroup Boolean to indicate if the files are associated with a group or item
1247
- * @internal
1248
- */
1249
- function _applySourceToDeployOptions(deployOptions, solutionTemplateBase, templateDictionary, authentication) {
1250
- // Deploy a solution from the template's contents,
1251
- // using the template's information as defaults for the deployed solution item
1252
- ["title", "snippet", "description", "tags"].forEach(function (prop) {
1253
- var _a;
1254
- deployOptions[prop] = (_a = deployOptions[prop]) !== null && _a !== void 0 ? _a : solutionTemplateBase[prop];
1255
- if (deployOptions[prop]) {
1256
- solutionTemplateBase[prop] = deployOptions[prop];
1257
- // carry these options forward on the templateDict
1258
- templateDictionary[prop] = deployOptions[prop];
1259
- }
1260
- });
1261
- if (!deployOptions.thumbnailurl && solutionTemplateBase.thumbnail) {
1262
- // Get the full path to the thumbnail
1263
- deployOptions.thumbnailurl = common.generateSourceThumbnailUrl(authentication.portal, solutionTemplateBase.id, solutionTemplateBase.thumbnail);
1264
- delete solutionTemplateBase.thumbnail;
1265
- }
1266
- return deployOptions;
1267
- }
1268
- function _replaceParamVariables(solutionTemplateData, templateDictionary) {
1269
- // a custom params object can be passed in with the options to deploy a solution
1270
- // in most cases we can defer to the item type handlers to use these values
1271
- // for variable replacement
1272
- // for spatial reference specifically we need to replace up front so the default extent
1273
- // logic can execute as expected
1274
- solutionTemplateData.templates = solutionTemplateData.templates.map(function (template) {
1275
- // can't do this as it causes other values that don't exist in the dict yet to revert to defaults they may have defined
1276
- // return common.replaceInTemplate(template, templateDictionary);
1277
- /* istanbul ignore else */
1278
- if (template.type === "Feature Service") {
1279
- var paramsLookup = "params.";
1280
- var wkidItemPath = "item.spatialReference.wkid";
1281
- template = _updateProp(template, wkidItemPath, paramsLookup, templateDictionary);
1282
- var wkidServicePath = "properties.service.spatialReference.wkid";
1283
- template = _updateProp(template, wkidServicePath, paramsLookup, templateDictionary);
1284
- }
1285
- return template;
1286
- });
1287
- }
1288
- function _updateProp(template, path, lookup, templateDictionary) {
1289
- var wkid = common.getProp(template, path);
1290
- /* istanbul ignore else */
1291
- if (wkid && typeof wkid === "string" && wkid.indexOf(lookup) > -1) {
1292
- common.setProp(template, path, common.replaceInTemplate(wkid, templateDictionary));
1293
- }
1294
- return template;
1295
- }
1296
- function _checkedReplaceAll(template, oldValue, newValue) {
1297
- var newTemplate;
1298
- if (template && template.indexOf(oldValue) > -1) {
1299
- var re = new RegExp(oldValue, "g");
1300
- newTemplate = template.replace(re, newValue);
1301
- }
1302
- else {
1303
- newTemplate = template;
1304
- }
1305
- return newTemplate;
1306
- }
1307
- function _getPortalBaseUrl(portalResponse, authentication) {
1308
- // As of Spring 2020, only HTTPS (see
1309
- // https://www.esri.com/arcgis-blog/products/product/administration/2019-arcgis-transport-security-improvements/)
1310
- var scheme = "https"; // portalResponse.allSSL ? "https" : "http";
1311
- var urlKey = common.getProp(portalResponse, "urlKey");
1312
- var customBaseUrl = common.getProp(portalResponse, "customBaseUrl");
1313
- var enterpriseBaseUrl = common.getProp(portalResponse, "portalHostname");
1314
- return urlKey && customBaseUrl
1315
- ? scheme + "://" + urlKey + "." + customBaseUrl
1316
- : enterpriseBaseUrl
1317
- ? scheme + "://" + enterpriseBaseUrl
1318
- : authentication.portal.replace("/sharing/rest", "");
1319
- }
1320
- function _updateGroupReferences(itemTemplates, templateDictionary) {
1321
- var groupIds = itemTemplates.reduce(function (result, t) {
1322
- if (t.type === "Group") {
1323
- result.push(t.itemId);
1324
- }
1325
- return result;
1326
- }, []);
1327
- Object.keys(templateDictionary).forEach(function (k) {
1328
- var newId = templateDictionary[k].itemId;
1329
- if (groupIds.indexOf(newId) > -1) {
1330
- itemTemplates.forEach(function (t) {
1331
- t.groups = t.groups.map(function (id) { return (id === k ? newId : id); });
1332
- });
1333
- }
1334
- });
1335
- return itemTemplates;
1336
- }
1337
- function _purgeTemplateProperties(itemTemplate) {
1338
- var retainProps = ["itemId", "type", "dependencies", "groups"];
1339
- var deleteProps = Object.keys(itemTemplate).filter(function (k) { return retainProps.indexOf(k) < 0; });
1340
- common.deleteProps(itemTemplate, deleteProps);
1341
- return itemTemplate;
1342
- }
1418
+ /** @license
1419
+ * Copyright 2018 Esri
1420
+ *
1421
+ * Licensed under the Apache License, Version 2.0 (the "License");
1422
+ * you may not use this file except in compliance with the License.
1423
+ * You may obtain a copy of the License at
1424
+ *
1425
+ * http://www.apache.org/licenses/LICENSE-2.0
1426
+ *
1427
+ * Unless required by applicable law or agreed to in writing, software
1428
+ * distributed under the License is distributed on an "AS IS" BASIS,
1429
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1430
+ * See the License for the specific language governing permissions and
1431
+ * limitations under the License.
1432
+ */
1433
+ /**
1434
+ * Given an itemId or an object, either fetch the item or
1435
+ * resolve using the object, if it is structured as expected
1436
+ *
1437
+ * @param idOrObject string || object like `{item:{...}, data: {...}}`
1438
+ * @param authentication UserSession
1439
+ */
1440
+ function getSolutionTemplateItem(idOrObject, authentication) {
1441
+ if (typeof idOrObject === "string") {
1442
+ // get the item + data
1443
+ return Promise.all([
1444
+ common.getItemBase(idOrObject, authentication),
1445
+ common.getItemDataAsJson(idOrObject, authentication)
1446
+ ]).then(([item, data]) => {
1447
+ // format into a model and migrate the schema
1448
+ return common.migrateSchema({
1449
+ item,
1450
+ data
1451
+ });
1452
+ });
1453
+ }
1454
+ else {
1455
+ // check if it is a "Model"
1456
+ if (_isModel(idOrObject)) {
1457
+ // run migrations
1458
+ return common.migrateSchema(idOrObject);
1459
+ }
1460
+ else {
1461
+ return Promise.reject(common.fail(`getSolutionTemplateItem must be passed an item id or a model object`));
1462
+ }
1463
+ }
1464
+ }
1465
+ /**
1466
+ * Update the Deploy Options with information from the
1467
+ * Solution Template item
1468
+ *
1469
+ * @param deployOptions
1470
+ * @param item
1471
+ * @param authentication
1472
+ */
1473
+ function updateDeployOptions(deployOptions, item, authentication) {
1474
+ deployOptions.jobId = deployOptions.jobId ?? item.id;
1475
+ deployOptions.title = deployOptions.title ?? item.title;
1476
+ deployOptions.snippet = deployOptions.snippet ?? item.snippet;
1477
+ deployOptions.description = deployOptions.description ?? item.description;
1478
+ deployOptions.tags = deployOptions.tags ?? item.tags;
1479
+ // add the thumbnail url
1480
+ deployOptions.thumbnailurl = item.thumbnail
1481
+ ? common.getItemThumbnailUrl(item.id, item.thumbnail, false, authentication)
1482
+ : null;
1483
+ return deployOptions;
1484
+ }
1485
+ /**
1486
+ * Check if an object is an Model
1487
+ *
1488
+ * @param obj any object
1489
+ */
1490
+ function _isModel(obj) {
1491
+ let result = false;
1492
+ // TODO Hoist into common?
1493
+ const isNotStringOrArray = (v) => v != null &&
1494
+ typeof v !== "string" &&
1495
+ !Array.isArray(v) &&
1496
+ typeof v === "object";
1497
+ if (isNotStringOrArray(obj)) {
1498
+ result = ["item", "data"].reduce((acc, prop) => {
1499
+ if (acc) {
1500
+ acc = isNotStringOrArray(obj[prop]);
1501
+ }
1502
+ return acc;
1503
+ }, true);
1504
+ }
1505
+ return result;
1506
+ }
1507
+ /**
1508
+ * Does the item have the correct type and keywords
1509
+ * to be a Solution Template item?
1510
+ *
1511
+ * @param item IItem
1512
+ */
1513
+ function isSolutionTemplateItem(item) {
1514
+ const kwds = item.typeKeywords;
1515
+ // Solution items
1516
+ let result = false;
1517
+ if (item.type === "Solution") {
1518
+ if (kwds.indexOf("Solution") > -1 &&
1519
+ (kwds.indexOf("Template") > -1 || kwds.indexOf("solutionTemplate") > -1)) {
1520
+ result = true;
1521
+ }
1522
+ }
1523
+ // Older Hub Solutions used Web Mapping Application items
1524
+ if (item.type === "Web Mapping Application") {
1525
+ if (kwds.indexOf("hubSolutionTemplate") > -1) {
1526
+ result = true;
1527
+ }
1528
+ }
1529
+ return result;
1530
+ }
1343
1531
 
1344
- /** @license
1345
- * Copyright 2018 Esri
1346
- *
1347
- * Licensed under the Apache License, Version 2.0 (the "License");
1348
- * you may not use this file except in compliance with the License.
1349
- * You may obtain a copy of the License at
1350
- *
1351
- * http://www.apache.org/licenses/LICENSE-2.0
1352
- *
1353
- * Unless required by applicable law or agreed to in writing, software
1354
- * distributed under the License is distributed on an "AS IS" BASIS,
1355
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1356
- * See the License for the specific language governing permissions and
1357
- * limitations under the License.
1358
- */
1359
- /**
1360
- * Given an itemId or an object, either fetch the item or
1361
- * resolve using the object, if it is structured as expected
1362
- *
1363
- * @param idOrObject string || object like `{item:{...}, data: {...}}`
1364
- * @param authentication UserSession
1365
- */
1366
- function getSolutionTemplateItem(idOrObject, authentication) {
1367
- if (typeof idOrObject === "string") {
1368
- // get the item + data
1369
- return Promise.all([
1370
- common.getItemBase(idOrObject, authentication),
1371
- common.getItemDataAsJson(idOrObject, authentication)
1372
- ]).then(function (_a) {
1373
- var _b = __read(_a, 2), item = _b[0], data = _b[1];
1374
- // format into a model and migrate the schema
1375
- return common.migrateSchema({
1376
- item: item,
1377
- data: data
1378
- });
1379
- });
1380
- }
1381
- else {
1382
- // check if it is a "Model"
1383
- if (_isModel(idOrObject)) {
1384
- // run migrations
1385
- return common.migrateSchema(idOrObject);
1386
- }
1387
- else {
1388
- return Promise.reject(common.fail("getSolutionTemplateItem must be passed an item id or a model object"));
1389
- }
1390
- }
1391
- }
1392
- /**
1393
- * Update the Deploy Options with information from the
1394
- * Solution Template item
1395
- *
1396
- * @param deployOptions
1397
- * @param item
1398
- * @param authentication
1399
- */
1400
- function updateDeployOptions(deployOptions, item, authentication) {
1401
- var _a, _b, _c, _d, _e;
1402
- deployOptions.jobId = (_a = deployOptions.jobId) !== null && _a !== void 0 ? _a : item.id;
1403
- deployOptions.title = (_b = deployOptions.title) !== null && _b !== void 0 ? _b : item.title;
1404
- deployOptions.snippet = (_c = deployOptions.snippet) !== null && _c !== void 0 ? _c : item.snippet;
1405
- deployOptions.description = (_d = deployOptions.description) !== null && _d !== void 0 ? _d : item.description;
1406
- deployOptions.tags = (_e = deployOptions.tags) !== null && _e !== void 0 ? _e : item.tags;
1407
- // add the thumbnail url
1408
- deployOptions.thumbnailurl = item.thumbnail
1409
- ? common.getItemThumbnailUrl(item.id, item.thumbnail, false, authentication)
1410
- : null;
1411
- return deployOptions;
1412
- }
1413
- /**
1414
- * Check if an object is an Model
1415
- *
1416
- * @param obj any object
1417
- */
1418
- function _isModel(obj) {
1419
- var result = false;
1420
- // TODO Hoist into common?
1421
- var isNotStringOrArray = function (v) {
1422
- return v != null &&
1423
- typeof v !== "string" &&
1424
- !Array.isArray(v) &&
1425
- typeof v === "object";
1426
- };
1427
- if (isNotStringOrArray(obj)) {
1428
- result = ["item", "data"].reduce(function (acc, prop) {
1429
- if (acc) {
1430
- acc = isNotStringOrArray(obj[prop]);
1431
- }
1432
- return acc;
1433
- }, true);
1434
- }
1435
- return result;
1436
- }
1437
- /**
1438
- * Does the item have the correct type and keywords
1439
- * to be a Solution Template item?
1440
- *
1441
- * @param item IItem
1442
- */
1443
- function isSolutionTemplateItem(item) {
1444
- var kwds = item.typeKeywords;
1445
- // Solution items
1446
- var result = false;
1447
- if (item.type === "Solution") {
1448
- if (kwds.indexOf("Solution") > -1 &&
1449
- (kwds.indexOf("Template") > -1 || kwds.indexOf("solutionTemplate") > -1)) {
1450
- result = true;
1451
- }
1452
- }
1453
- // Older Hub Solutions used Web Mapping Application items
1454
- if (item.type === "Web Mapping Application") {
1455
- if (kwds.indexOf("hubSolutionTemplate") > -1) {
1456
- result = true;
1457
- }
1458
- }
1459
- return result;
1460
- }
1532
+ /** @license
1533
+ * Copyright 2018 Esri
1534
+ *
1535
+ * Licensed under the Apache License, Version 2.0 (the "License");
1536
+ * you may not use this file except in compliance with the License.
1537
+ * You may obtain a copy of the License at
1538
+ *
1539
+ * http://www.apache.org/licenses/LICENSE-2.0
1540
+ *
1541
+ * Unless required by applicable law or agreed to in writing, software
1542
+ * distributed under the License is distributed on an "AS IS" BASIS,
1543
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1544
+ * See the License for the specific language governing permissions and
1545
+ * limitations under the License.
1546
+ */
1547
+ /**
1548
+ * Deploy a Solution
1549
+ *
1550
+ * Pass in either the item id or an IModel (`{item:{}, model:{}}`)
1551
+ * of a Solution Template, and this will generate the Solution
1552
+ *
1553
+ * @param maybeModel Item Id or IModel
1554
+ * @param authentication Credentials for the destination organization
1555
+ * @param options Options to override deployed information and to provide additional credentials
1556
+ * @return The id of the created deployed solution item
1557
+ */
1558
+ function deploySolution(maybeModel, authentication, options) {
1559
+ // if we are not passed the maybeModel, reject
1560
+ if (!maybeModel) {
1561
+ return Promise.reject(common.fail("The Solution Template id is missing"));
1562
+ }
1563
+ let deployOptions = options || {};
1564
+ /* istanbul ignore else */
1565
+ if (deployOptions.progressCallback) {
1566
+ deployOptions.progressCallback(1, deployOptions.jobId); // let the caller know that we've started
1567
+ }
1568
+ // It is possible to provide a separate authentication for the source
1569
+ const storageAuthentication = deployOptions.storageAuthentication
1570
+ ? deployOptions.storageAuthentication
1571
+ : authentication;
1572
+ // deal with maybe getting an item or an id
1573
+ return getSolutionTemplateItem(maybeModel, storageAuthentication)
1574
+ .then(model => {
1575
+ if (!isSolutionTemplateItem(model.item)) {
1576
+ return Promise.reject(common.fail(`${model.item.id} is not a Solution Template`));
1577
+ }
1578
+ else {
1579
+ // fetch the metadata if the model's id is a GUID and pass the item & data forward
1580
+ return Promise.all([
1581
+ Promise.resolve(model.item),
1582
+ Promise.resolve(model.data)
1583
+ ]);
1584
+ }
1585
+ })
1586
+ .then(responses => {
1587
+ // extract responses
1588
+ const [itemBase, itemData] = responses;
1589
+ // sanitize all the things
1590
+ const sanitizer = new common.Sanitizer();
1591
+ const item = common.sanitizeJSONAndReportChanges(itemBase, sanitizer);
1592
+ // TODO: we should delegate data sanization to the type-specific modules
1593
+ const data = itemData;
1594
+ // get the item id before it is deleted
1595
+ const itemId = item.id;
1596
+ // apply item props to deployOptions
1597
+ deployOptions = updateDeployOptions(deployOptions, item, storageAuthentication);
1598
+ // Clone before mutating? This was messing me up in some testing...
1599
+ common.deleteItemProps(item);
1600
+ return deploySolutionFromTemplate(itemId, item, data, authentication, deployOptions);
1601
+ })
1602
+ .then(createdSolutionId => {
1603
+ /* istanbul ignore else */
1604
+ if (deployOptions.progressCallback) {
1605
+ deployOptions.progressCallback(100, deployOptions.jobId); // we're done
1606
+ }
1607
+ return createdSolutionId;
1608
+ }, error => {
1609
+ // Error deploying solution
1610
+ /* istanbul ignore else */
1611
+ if (deployOptions.progressCallback) {
1612
+ deployOptions.progressCallback(1, deployOptions.jobId);
1613
+ }
1614
+ return Promise.reject(error);
1615
+ })
1616
+ .catch(ex => {
1617
+ throw ex;
1618
+ });
1619
+ }
1461
1620
 
1462
- /** @license
1463
- * Copyright 2018 Esri
1464
- *
1465
- * Licensed under the Apache License, Version 2.0 (the "License");
1466
- * you may not use this file except in compliance with the License.
1467
- * You may obtain a copy of the License at
1468
- *
1469
- * http://www.apache.org/licenses/LICENSE-2.0
1470
- *
1471
- * Unless required by applicable law or agreed to in writing, software
1472
- * distributed under the License is distributed on an "AS IS" BASIS,
1473
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1474
- * See the License for the specific language governing permissions and
1475
- * limitations under the License.
1476
- */
1477
- /**
1478
- * Deploy a Solution
1479
- *
1480
- * Pass in either the item id or an IModel (`{item:{}, model:{}}`)
1481
- * of a Solution Template, and this will generate the Solution
1482
- *
1483
- * @param maybeModel Item Id or IModel
1484
- * @param authentication Credentials for the destination organization
1485
- * @param options Options to override deployed information and to provide additional credentials
1486
- * @return The id of the created deployed solution item
1487
- */
1488
- function deploySolution(maybeModel, authentication, options) {
1489
- // if we are not passed the maybeModel, reject
1490
- if (!maybeModel) {
1491
- return Promise.reject(common.fail("The Solution Template id is missing"));
1492
- }
1493
- var deployOptions = options || {};
1494
- /* istanbul ignore else */
1495
- if (deployOptions.progressCallback) {
1496
- deployOptions.progressCallback(1); // let the caller know that we've started
1497
- }
1498
- // It is possible to provide a separate authentication for the source
1499
- var storageAuthentication = deployOptions.storageAuthentication
1500
- ? deployOptions.storageAuthentication
1501
- : authentication;
1502
- // deal with maybe getting an item or an id
1503
- return getSolutionTemplateItem(maybeModel, storageAuthentication)
1504
- .then(function (model) {
1505
- if (!isSolutionTemplateItem(model.item)) {
1506
- return Promise.reject(common.fail(model.item.id + " is not a Solution Template"));
1507
- }
1508
- else {
1509
- // fetch the metadata if the model's id is a GUID and pass the item & data forward
1510
- return Promise.all([
1511
- Promise.resolve(model.item),
1512
- Promise.resolve(model.data)
1513
- ]);
1514
- }
1515
- })
1516
- .then(function (responses) {
1517
- // extract responses
1518
- var _a = __read(responses, 2), itemBase = _a[0], itemData = _a[1];
1519
- // sanitize all the things
1520
- var sanitizer = new common.Sanitizer();
1521
- var item = common.sanitizeJSONAndReportChanges(itemBase, sanitizer);
1522
- // TODO: we should delegate data sanization to the type-specific modules
1523
- var data = itemData;
1524
- // get the item id before it is deleted
1525
- var itemId = item.id;
1526
- // apply item props to deployOptions
1527
- deployOptions = updateDeployOptions(deployOptions, item, storageAuthentication);
1528
- // Clone before mutating? This was messing me up in some testing...
1529
- common.deleteItemProps(item);
1530
- return deploySolutionFromTemplate(itemId, item, data, authentication, deployOptions);
1531
- })
1532
- .then(function (createdSolutionId) {
1533
- /* istanbul ignore else */
1534
- if (deployOptions.progressCallback) {
1535
- deployOptions.progressCallback(100); // we're done
1536
- }
1537
- return createdSolutionId;
1538
- }, function (error) {
1539
- // Error deploying solution
1540
- /* istanbul ignore else */
1541
- if (deployOptions.progressCallback) {
1542
- deployOptions.progressCallback(1);
1543
- }
1544
- return Promise.reject(error);
1545
- })
1546
- .catch(function (ex) {
1547
- throw ex;
1548
- });
1549
- }
1621
+ exports.UNSUPPORTED = UNSUPPORTED;
1622
+ exports._createItemFromTemplateWhenReady = _createItemFromTemplateWhenReady;
1623
+ exports._estimateDeploymentCost = _estimateDeploymentCost;
1624
+ exports._evaluateSharedViewSources = _evaluateSharedViewSources;
1625
+ exports._findExistingItem = _findExistingItem;
1626
+ exports._findExistingItemByKeyword = _findExistingItemByKeyword;
1627
+ exports._flagPatchItemsForPostProcessing = _flagPatchItemsForPostProcessing;
1628
+ exports._getGroupUpdates = _getGroupUpdates;
1629
+ exports._getViewHash = _getViewHash;
1630
+ exports._getViews = _getViews;
1631
+ exports._handleExistingItems = _handleExistingItems;
1632
+ exports._isModel = _isModel;
1633
+ exports._reuseDeployedItems = _reuseDeployedItems;
1634
+ exports._setFields = _setFields;
1635
+ exports._setTypekeywordForExisting = _setTypekeywordForExisting;
1636
+ exports._updateTemplateDictionary = _updateTemplateDictionary;
1637
+ exports._updateTemplateDictionaryById = _updateTemplateDictionaryById;
1638
+ exports._updateTemplateDictionaryForError = _updateTemplateDictionaryForError;
1639
+ exports._updateViewTemplates = _updateViewTemplates;
1640
+ exports._useExistingItems = _useExistingItems;
1641
+ exports.deploySolution = deploySolution;
1642
+ exports.deploySolutionItems = deploySolutionItems;
1643
+ exports.getSolutionTemplateItem = getSolutionTemplateItem;
1644
+ exports.isSolutionTemplateItem = isSolutionTemplateItem;
1645
+ exports.moduleMap = moduleMap;
1646
+ exports.updateDeployOptions = updateDeployOptions;
1550
1647
 
1551
- exports.UNSUPPORTED = UNSUPPORTED;
1552
- exports._createItemFromTemplateWhenReady = _createItemFromTemplateWhenReady;
1553
- exports._estimateDeploymentCost = _estimateDeploymentCost;
1554
- exports._evaluateSharedViewSources = _evaluateSharedViewSources;
1555
- exports._findExistingItem = _findExistingItem;
1556
- exports._findExistingItemByKeyword = _findExistingItemByKeyword;
1557
- exports._flagPatchItemsForPostProcessing = _flagPatchItemsForPostProcessing;
1558
- exports._getGroupUpdates = _getGroupUpdates;
1559
- exports._getViewHash = _getViewHash;
1560
- exports._getViews = _getViews;
1561
- exports._handleExistingItems = _handleExistingItems;
1562
- exports._isModel = _isModel;
1563
- exports._reuseDeployedItems = _reuseDeployedItems;
1564
- exports._updateTemplateDictionary = _updateTemplateDictionary;
1565
- exports._updateTemplateDictionaryById = _updateTemplateDictionaryById;
1566
- exports._updateTemplateDictionaryForError = _updateTemplateDictionaryForError;
1567
- exports._updateViewTemplates = _updateViewTemplates;
1568
- exports._useExistingItems = _useExistingItems;
1569
- exports.deploySolution = deploySolution;
1570
- exports.deploySolutionItems = deploySolutionItems;
1571
- exports.getSolutionTemplateItem = getSolutionTemplateItem;
1572
- exports.isSolutionTemplateItem = isSolutionTemplateItem;
1573
- exports.moduleMap = moduleMap;
1574
- exports.updateDeployOptions = updateDeployOptions;
1575
-
1576
- Object.defineProperty(exports, '__esModule', { value: true });
1648
+ Object.defineProperty(exports, '__esModule', { value: true });
1577
1649
 
1578
1650
  })));
1579
1651
  //# sourceMappingURL=deployer.umd.js.map