@esri/solution-simple-types 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/esm/dashboard.d.ts +0 -1
  2. package/dist/esm/dashboard.js +55 -56
  3. package/dist/esm/dashboard.js.map +1 -1
  4. package/dist/esm/helpers/convert-item-to-template.d.ts +3 -2
  5. package/dist/esm/helpers/convert-item-to-template.js +35 -37
  6. package/dist/esm/helpers/convert-item-to-template.js.map +1 -1
  7. package/dist/esm/helpers/create-item-from-template.js +33 -41
  8. package/dist/esm/helpers/create-item-from-template.js.map +1 -1
  9. package/dist/esm/helpers/update-notebook-data.js +1 -1
  10. package/dist/esm/helpers/update-notebook-data.js.map +1 -1
  11. package/dist/esm/notebook.d.ts +3 -2
  12. package/dist/esm/notebook.js +16 -15
  13. package/dist/esm/notebook.js.map +1 -1
  14. package/dist/esm/oic.d.ts +3 -2
  15. package/dist/esm/oic.js +30 -29
  16. package/dist/esm/oic.js.map +1 -1
  17. package/dist/esm/quickcapture.d.ts +3 -2
  18. package/dist/esm/quickcapture.js +22 -21
  19. package/dist/esm/quickcapture.js.map +1 -1
  20. package/dist/esm/simple-types.d.ts +3 -2
  21. package/dist/esm/simple-types.js +4 -3
  22. package/dist/esm/simple-types.js.map +1 -1
  23. package/dist/esm/webmap.d.ts +3 -2
  24. package/dist/esm/webmap.js +39 -39
  25. package/dist/esm/webmap.js.map +1 -1
  26. package/dist/esm/webmappingapplication.d.ts +3 -2
  27. package/dist/esm/webmappingapplication.js +126 -128
  28. package/dist/esm/webmappingapplication.js.map +1 -1
  29. package/dist/esm/workforce.d.ts +3 -2
  30. package/dist/esm/workforce.js +4 -3
  31. package/dist/esm/workforce.js.map +1 -1
  32. package/dist/node/dashboard.d.ts +0 -1
  33. package/dist/node/dashboard.js +56 -57
  34. package/dist/node/dashboard.js.map +1 -1
  35. package/dist/node/helpers/convert-item-to-template.d.ts +3 -2
  36. package/dist/node/helpers/convert-item-to-template.js +43 -45
  37. package/dist/node/helpers/convert-item-to-template.js.map +1 -1
  38. package/dist/node/helpers/create-item-from-template.js +37 -45
  39. package/dist/node/helpers/create-item-from-template.js.map +1 -1
  40. package/dist/node/helpers/notebook-helpers.js +3 -3
  41. package/dist/node/helpers/notebook-helpers.js.map +1 -1
  42. package/dist/node/helpers/quickcapture-helpers.js +2 -2
  43. package/dist/node/helpers/quickcapture-helpers.js.map +1 -1
  44. package/dist/node/helpers/simple-type-helpers.js +2 -2
  45. package/dist/node/helpers/simple-type-helpers.js.map +1 -1
  46. package/dist/node/helpers/update-notebook-data.js +2 -2
  47. package/dist/node/helpers/update-notebook-data.js.map +1 -1
  48. package/dist/node/index.js +6 -6
  49. package/dist/node/index.js.map +1 -1
  50. package/dist/node/notebook.d.ts +3 -2
  51. package/dist/node/notebook.js +18 -17
  52. package/dist/node/notebook.js.map +1 -1
  53. package/dist/node/oic.d.ts +3 -2
  54. package/dist/node/oic.js +31 -30
  55. package/dist/node/oic.js.map +1 -1
  56. package/dist/node/quickcapture.d.ts +3 -2
  57. package/dist/node/quickcapture.js +24 -23
  58. package/dist/node/quickcapture.js.map +1 -1
  59. package/dist/node/simple-types.d.ts +3 -2
  60. package/dist/node/simple-types.js +9 -8
  61. package/dist/node/simple-types.js.map +1 -1
  62. package/dist/node/webmap.d.ts +3 -2
  63. package/dist/node/webmap.js +40 -40
  64. package/dist/node/webmap.js.map +1 -1
  65. package/dist/node/webmappingapplication.d.ts +3 -2
  66. package/dist/node/webmappingapplication.js +127 -129
  67. package/dist/node/webmappingapplication.js.map +1 -1
  68. package/dist/node/workforce.d.ts +3 -2
  69. package/dist/node/workforce.js +5 -4
  70. package/dist/node/workforce.js.map +1 -1
  71. package/dist/umd/dashboard.d.ts +0 -1
  72. package/dist/umd/helpers/convert-item-to-template.d.ts +3 -2
  73. package/dist/umd/notebook.d.ts +3 -2
  74. package/dist/umd/oic.d.ts +3 -2
  75. package/dist/umd/quickcapture.d.ts +3 -2
  76. package/dist/umd/simple-types.d.ts +3 -2
  77. package/dist/umd/simple-types.umd.js +2142 -2152
  78. package/dist/umd/simple-types.umd.js.map +1 -1
  79. package/dist/umd/simple-types.umd.min.js +3 -3
  80. package/dist/umd/simple-types.umd.min.js.map +1 -1
  81. package/dist/umd/webmap.d.ts +3 -2
  82. package/dist/umd/webmappingapplication.d.ts +3 -2
  83. package/dist/umd/workforce.d.ts +3 -2
  84. package/package.json +23 -23
@@ -1,7 +1,7 @@
1
1
  /* @preserve
2
- * @esri/solution-simple-types - v1.1.2 - Apache-2.0
2
+ * @esri/solution-simple-types - v1.2.0 - Apache-2.0
3
3
  * Copyright (c) 2018-2021 Esri, Inc.
4
- * Tue Aug 31 2021 00:00:46 GMT-0700 (Pacific Daylight Time)
4
+ * Thu Dec 09 2021 16:04:06 GMT-0800 (Pacific Standard 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,2179 +16,2169 @@
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')) :
20
- typeof define === 'function' && define.amd ? define(['exports', '@esri/solution-common'], factory) :
21
- (global = global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution));
22
- }(this, (function (exports, common) { 'use strict';
19
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/solution-common')) :
20
+ typeof define === 'function' && define.amd ? define(['exports', '@esri/solution-common'], factory) :
21
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution));
22
+ })(this, (function (exports, common) { '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
- function __read(o, n) {
40
- var m = typeof Symbol === "function" && o[Symbol.iterator];
41
- if (!m) return o;
42
- var i = m.call(o), r, ar = [], e;
43
- try {
44
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
45
- }
46
- catch (error) { e = { error: error }; }
47
- finally {
48
- try {
49
- if (r && !r.done && (m = i["return"])) m.call(i);
50
- }
51
- finally { if (e) throw e.error; }
52
- }
53
- return ar;
24
+ function _interopNamespace(e) {
25
+ if (e && e.__esModule) return e;
26
+ var n = Object.create(null);
27
+ if (e) {
28
+ Object.keys(e).forEach(function (k) {
29
+ if (k !== 'default') {
30
+ var d = Object.getOwnPropertyDescriptor(e, k);
31
+ Object.defineProperty(n, k, d.get ? d : {
32
+ enumerable: true,
33
+ get: function () { return e[k]; }
34
+ });
35
+ }
36
+ });
54
37
  }
38
+ n["default"] = e;
39
+ return Object.freeze(n);
40
+ }
55
41
 
56
- /** @license
57
- * Copyright 2018 Esri
58
- *
59
- * Licensed under the Apache License, Version 2.0 (the "License");
60
- * you may not use this file except in compliance with the License.
61
- * You may obtain a copy of the License at
62
- *
63
- * http://www.apache.org/licenses/LICENSE-2.0
64
- *
65
- * Unless required by applicable law or agreed to in writing, software
66
- * distributed under the License is distributed on an "AS IS" BASIS,
67
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
68
- * See the License for the specific language governing permissions and
69
- * limitations under the License.
70
- */
71
- /**
72
- * Converts a dashboard item to a template.
73
- *
74
- * @param itemTemplate Template for the dashboard item
75
- * @param authentication Credentials for any requests
76
- * @return templatized itemTemplate
77
- */
78
- function convertItemToTemplate(itemTemplate) {
79
- return _extractDependencies(itemTemplate);
80
- }
81
- /**
82
- * Templatizes all itemIds and updates the dependency array
83
- *
84
- * @param itemTemplate Template for the dashboard item
85
- * @return The updated itemTemplate
86
- * @protected
87
- */
88
- function _extractDependencies(itemTemplate) {
89
- // get dependencies from any
90
- var updatePaths = [
91
- "data.widgets",
92
- "data.headerPanel.selectors",
93
- "data.leftPanel.selectors",
94
- "data.urlParameters"
95
- ];
96
- updatePaths.forEach(function (path) {
97
- var objs = common.getProp(itemTemplate, path);
98
- if (Array.isArray(objs)) {
99
- objs.forEach(function (obj) {
100
- /* istanbul ignore else */
101
- if (obj.type === "mapWidget") {
102
- /* istanbul ignore else */
103
- if (itemTemplate.dependencies.indexOf(obj.itemId) < 0) {
104
- itemTemplate.dependencies.push(obj.itemId);
105
- }
106
- obj.itemId = common.templatizeTerm(obj.itemId, obj.itemId, ".itemId");
107
- }
108
- /* istanbul ignore else */
109
- if (Array.isArray(obj.datasets)) {
110
- _getDatasourceDependencies(obj, itemTemplate);
111
- }
112
- });
113
- }
114
- });
115
- return itemTemplate;
116
- }
117
- /**
118
- * Templatize datasource itemIds and update the dependency array
119
- *
120
- * @param obj A widget, selector, or urlParameter that contains a datasets collection
121
- * @param itemTemplate Template for the dashboard item
122
- */
123
- function _getDatasourceDependencies(obj, itemTemplate) {
124
- obj.datasets.forEach(function (dataset) {
125
- // when the datasource has an itemId is an external datasource
126
- var itemId = common.getProp(dataset, "dataSource.itemId");
127
- if (itemId) {
128
- if (itemTemplate.dependencies.indexOf(itemId) < 0) {
129
- itemTemplate.dependencies.push(itemId);
130
- }
131
- var layerId = common.getProp(dataset, "dataSource.layerId");
132
- dataset.dataSource.itemId = common.templatizeTerm(itemId, itemId, layerId !== undefined ? ".layer" + layerId + ".itemId" : ".itemId");
133
- /* istanbul ignore else */
134
- if (layerId !== undefined) {
135
- dataset.dataSource.layerId = common.templatizeTerm(itemId, itemId, ".layer" + layerId + ".layerId");
136
- }
137
- }
138
- });
139
- }
140
- /**
141
- * Templatize field references for datasources and widgets.
142
- *
143
- * @param solutionTemplate The solution item template
144
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
145
- * @returns The solutionTemplate with templatized field references
146
- */
147
- function postProcessFieldReferences(solutionTemplate, datasourceInfos) {
148
- var updatePaths = [
149
- "data.widgets",
150
- "data.headerPanel.selectors",
151
- "data.leftPanel.selectors",
152
- "data.urlParameters"
153
- ];
154
- // dashboards reference datasets from other widgets
155
- // add reference IDs to the appropriate datasourceInfos
156
- updatePaths.forEach(function (path) {
157
- var objs = common.getProp(solutionTemplate, path);
158
- _updateDatasourceReferences(objs, datasourceInfos);
159
- });
160
- // after we know the potential references go ahead and templatize
161
- updatePaths.forEach(function (path) {
162
- _templatize(solutionTemplate, path, datasourceInfos);
163
- });
164
- return solutionTemplate;
165
- }
166
- /**
167
- * Add all dataset ids to the appropriate datasource info object so we can navigate any relative references
168
- *
169
- * @param objs Thes can be widgets, selectors, or urlParameters
170
- * @param datasourceInfos A list of objects that contain key details about the datasources from the application
171
- * @protected
172
- */
173
- function _updateDatasourceReferences(objs, datasourceInfos) {
174
- // objects can be events or widgets
175
- /* istanbul ignore else */
176
- if (objs && Array.isArray(objs)) {
177
- objs.forEach(function (obj) {
178
- if (Array.isArray(obj.datasets)) {
179
- obj.datasets.forEach(function (dataset) {
180
- // when the datasource has an itemId it's an external datasource
181
- var itemId = common.cleanLayerBasedItemId(common.getProp(dataset, "dataSource.itemId"));
182
- if (itemId) {
183
- var layerId_1 = common.cleanLayerId(common.getProp(dataset, "dataSource.layerId"));
184
- datasourceInfos.some(function (ds) {
185
- if (ds.itemId === itemId && ds.layerId === layerId_1) {
186
- _updateReferences(ds, obj.id);
187
- return true;
188
- }
189
- else {
190
- return false;
191
- }
192
- });
193
- }
194
- else {
195
- // add placeholder for map layer datasource info so we can know the items that reference them
196
- // needed when item field reference are derived from another widgets datasource eg. <dashboardWidgetId>#datasetname
197
- var id = common.getProp(dataset, "dataSource.id");
198
- if (id) {
199
- var dashboardLayerId_1 = id.split("#")[1];
200
- datasourceInfos.some(function (ds) {
201
- if (ds.ids.indexOf(dashboardLayerId_1) > -1) {
202
- _updateReferences(ds, obj.id);
203
- return true;
204
- }
205
- else {
206
- return false;
207
- }
208
- });
209
- }
210
- }
211
- });
212
- }
213
- });
214
- }
215
- }
216
- /**
217
- * Templatize all datasets and/or events for the objects at the given path
218
- *
219
- * @param itemTemplate Template for the dashboard item
220
- * @param path A property path to an array of objects that could contain datasets or events
221
- * @param datasourceInfos A list of objects that contain key details about the datasources from the application
222
- * @protected
223
- */
224
- function _templatize(itemTemplate, path, datasourceInfos) {
225
- var obj = common.getProp(itemTemplate, path);
226
- /* istanbul ignore else */
227
- if (obj) {
228
- common.setProp(itemTemplate, path, _templatizeByDatasource(obj, datasourceInfos));
229
- }
230
- }
231
- /**
232
- * For any service dataset datasource templatize all field references
233
- *
234
- * @param objs A list of objects that can contain field references
235
- * @param datasourceInfos A list of objects that contain key details about the datasources from the application
236
- * @return An updated list of objects with templatized field references
237
- * @protected
238
- */
239
- function _templatizeByDatasource(objs, datasourceInfos) {
240
- if (Array.isArray(objs)) {
241
- return objs.map(function (obj) {
242
- var _obj = obj;
243
- if (Array.isArray(_obj.events)) {
244
- // Events can be associated with datasets but they can also be associated with a target
245
- // In some cases an event will have a source and a target.
246
- // Handle these specifically first to ensure that it has the correct layer reference
247
- _obj.events = _obj.events.map(function (event) {
248
- var _event = event;
249
- /* istanbul ignore else */
250
- if (Array.isArray(_event.actions)) {
251
- _event.actions = _event.actions.map(function (action) {
252
- var _action = action;
253
- if (_action.fieldMap &&
254
- _action.targetId &&
255
- _action.targetId.indexOf("#") > -1) {
256
- var datasourceInfo = _getDatasourceInfo(_action, datasourceInfos);
257
- /* istanbul ignore else */
258
- if (datasourceInfo) {
259
- var fields_1 = common.getProp(datasourceInfo, "fields");
260
- var basePath_1 = common.getProp(datasourceInfo, "basePath");
261
- /* istanbul ignore else */
262
- if (Array.isArray(fields_1) && basePath_1) {
263
- _action.fieldMap = _action.fieldMap.map(function (m) {
264
- var _m = m;
265
- _m.targetName = common.templatizeFieldReferences(_m.targetName, fields_1, basePath_1);
266
- return _m;
267
- });
268
- }
269
- }
270
- }
271
- return _action;
272
- });
273
- }
274
- return _event;
275
- });
276
- }
277
- if (Array.isArray(_obj.datasets)) {
278
- _obj.datasets = _obj.datasets.map(function (dataset) {
279
- var _dataset = dataset;
280
- if (_dataset.type === "serviceDataset") {
281
- var datasourceInfo = _getDatasourceInfo(dataset, datasourceInfos);
282
- /* istanbul ignore else */
283
- if (datasourceInfo) {
284
- var fields = common.getProp(datasourceInfo, "fields");
285
- var basePath = common.getProp(datasourceInfo, "basePath");
286
- /* istanbul ignore else */
287
- if (Array.isArray(fields) && basePath) {
288
- _obj = common.templatizeFieldReferences(_obj, fields, basePath);
289
- _dataset = common.templatizeFieldReferences(_dataset, fields, basePath);
290
- }
291
- }
292
- }
293
- return _dataset;
294
- });
295
- return _obj;
296
- }
297
- else
298
- return _obj;
299
- });
300
- }
301
- else {
302
- return objs;
303
- }
304
- }
305
- /**
306
- * Find the appropriate datasource info object from the datasourceInfo collection
307
- *
308
- * @param obj Can be a Dataset or an event
309
- * @param datasourceInfos A list of objects that contain key details about the datasources from the application
310
- * @return The supporting datasource info for the given object
311
- * @protected
312
- */
313
- function _getDatasourceInfo(obj, datasourceInfos) {
314
- var info;
315
- // the datasource will have an id property when it's referencing a map layer
316
- // the fields collection will already be defined
317
- var id = common.getProp(obj, "dataSource.id") || common.getProp(obj, "targetId");
318
- if (id) {
319
- var dashboardLayerId_2 = id.split("#")[1];
320
- if (!datasourceInfos.some(function (di) {
321
- info = di.ids.indexOf(dashboardLayerId_2) > -1 ? di : info;
322
- return di.ids.indexOf(dashboardLayerId_2) > -1;
323
- })) {
324
- // in some cases the id will not contain a layer name...it will have the dashboard id for another widget
325
- // in that case lookup the datasource from referenced widget
326
- var dashboardWidgetId_1 = id.split("#")[0];
327
- datasourceInfos.some(function (di) {
328
- var references = di.references || [];
329
- var hasRef = references.indexOf(dashboardWidgetId_1) > -1;
330
- info = hasRef ? di : info;
331
- return hasRef;
332
- });
333
- }
334
- }
335
- else {
336
- // otherwise match the itemId and the layerId to get the correct fields and path
337
- var itemId_1 = common.cleanLayerBasedItemId(common.getProp(obj, "dataSource.itemId"));
338
- var layerId_2 = common.cleanLayerId(common.getProp(obj, "dataSource.layerId"));
339
- /* istanbul ignore else */
340
- if (itemId_1) {
341
- datasourceInfos.some(function (di) {
342
- var matches = itemId_1 === di.itemId && layerId_2 === di.layerId;
343
- info = matches ? di : info;
344
- return matches;
345
- });
346
- }
347
- }
348
- return info;
349
- }
350
- /**
351
- * Verifies if the datasource info contains the given id and adds it if not
352
- *
353
- * @param ds The datasource info to add the reference to
354
- * @param id The id from dashboard object, commonly another widget
355
- * @protected
356
- */
357
- function _updateReferences(ds, id) {
358
- ds.references = Array.isArray(ds.references) ? ds.references : [];
359
- if (ds.references.indexOf(id) < 0) {
360
- ds.references.push(id);
361
- }
362
- }
42
+ var common__namespace = /*#__PURE__*/_interopNamespace(common);
363
43
 
364
- /** @license
365
- * Copyright 2020 Esri
366
- *
367
- * Licensed under the Apache License, Version 2.0 (the "License");
368
- * you may not use this file except in compliance with the License.
369
- * You may obtain a copy of the License at
370
- *
371
- * http://www.apache.org/licenses/LICENSE-2.0
372
- *
373
- * Unless required by applicable law or agreed to in writing, software
374
- * distributed under the License is distributed on an "AS IS" BASIS,
375
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
376
- * See the License for the specific language governing permissions and
377
- * limitations under the License.
378
- */
379
- // ------------------------------------------------------------------------------------------------------------------ //
380
- /**
381
- * Converts a web mapping application item into a template.
382
- *
383
- * @param itemInfo Info about the item
384
- * @param authentication Credentials for working with AGO
385
- * @return A promise that will resolve when the template has been created
386
- */
387
- function convertItemToTemplate$1(itemTemplate, authentication) {
388
- return new Promise(function (resolve, reject) {
389
- // Remove org base URL and app id, e.g.,
390
- // http://anOrg.maps.arcgis.com/apps/CrowdsourcePolling/index.html?appid=6fc5992522d34a6b5ce80d17835eea21
391
- // to
392
- // <placeholder(SERVER_NAME)>/apps/CrowdsourcePolling/index.html?appid={{<itemId>.id}}
393
- // Need to add placeholder server name because otherwise AGOL makes URL null
394
- var portalUrl = "";
395
- if (itemTemplate.item.url) {
396
- var templatizedUrl = itemTemplate.item.url;
397
- var iSep = templatizedUrl.indexOf("//");
398
- itemTemplate.item.url =
399
- common.placeholder(common.SERVER_NAME) + // add placeholder server name
400
- templatizedUrl.substring(templatizedUrl.indexOf("/", iSep + 2), templatizedUrl.lastIndexOf("=") + 1) +
401
- itemTemplate.item.id; // templatized id
402
- portalUrl = templatizedUrl.replace(templatizedUrl.substring(templatizedUrl.indexOf("/", iSep + 2)), "");
403
- }
404
- // Extract dependencies
405
- itemTemplate.dependencies = _extractDependencies$1(itemTemplate);
406
- // Set the folder
407
- common.setProp(itemTemplate, "data.folderId", "{{folderId}}");
408
- // Set the map or group after we've extracted them as dependencies
409
- _templatizeIdPaths(itemTemplate, [
410
- "data.map.itemId",
411
- "data.map.appProxy.mapItemId",
412
- "data.values.webmap",
413
- "data.values.group"
414
- ]);
415
- // force the appItemId to be pulled directly from the template item
416
- // this is to address solution.js #124
417
- _templatizeIdPath(itemTemplate, "data.appItemId", itemTemplate.itemId);
418
- setValues(itemTemplate, [
419
- "data.logo",
420
- "data.map.portalUrl",
421
- "data.portalUrl",
422
- "data.httpProxy.url"
423
- ], common.placeholder(common.SERVER_NAME));
424
- common.setProp(itemTemplate, "data.geometryService", common.placeholder(common.GEOMETRY_SERVER_NAME));
425
- templatizeDatasources(itemTemplate, authentication, portalUrl).then(function () {
426
- templatizeWidgets(itemTemplate, authentication, portalUrl, "data.widgetPool.widgets").then(function (_itemTemplate) {
427
- templatizeWidgets(_itemTemplate, authentication, portalUrl, "data.widgetOnScreen.widgets", true).then(function (updatedItemTemplate) {
428
- templatizeValues(updatedItemTemplate, authentication, portalUrl, "data.values").then(function (_updatedItemTemplate) {
429
- resolve(_updatedItemTemplate);
430
- }, function (e) { return reject(common.fail(e)); });
431
- }, function (e) { return reject(common.fail(e)); });
432
- }, function (e) { return reject(common.fail(e)); });
433
- }, function (e) { return reject(common.fail(e)); });
434
- });
435
- }
436
- function templatizeDatasources(itemTemplate, authentication, portalUrl) {
437
- return new Promise(function (resolve, reject) {
438
- var dataSources = common.getProp(itemTemplate, "data.dataSource.dataSources");
439
- if (dataSources && Object.keys(dataSources).length > 0) {
440
- var pendingRequests_1 = new Array();
441
- Object.keys(dataSources).forEach(function (k) {
442
- var ds = dataSources[k];
443
- common.setProp(ds, "portalUrl", common.placeholder(common.SERVER_NAME));
444
- var itemId = common.getProp(ds, "itemId");
445
- if (common.getProp(ds, "url")) {
446
- if (itemId) {
447
- var layerId = ds.url.substr(ds.url.lastIndexOf("/") + 1);
448
- ds.itemId = common.templatizeTerm(itemId, itemId, ".layer" + layerId + ".itemId");
449
- }
450
- var urlResults_1 = findUrls(ds.url, portalUrl, [], [], authentication);
451
- pendingRequests_1.push(new Promise(function (resolveReq, rejectReq) {
452
- handleServiceRequests(urlResults_1.serviceRequests, urlResults_1.requestUrls, urlResults_1.testString).then(function (response) {
453
- ds.url = response;
454
- resolveReq();
455
- }, function (e) { return rejectReq(common.fail(e)); });
456
- }));
457
- }
458
- else {
459
- if (itemId) {
460
- ds.itemId = common.templatizeTerm(itemId, itemId, ".itemId");
461
- }
462
- }
463
- });
464
- Promise.all(pendingRequests_1).then(function () { return resolve(itemTemplate); }, function (e) { return reject(common.fail(e)); });
465
- }
466
- else {
467
- resolve(itemTemplate);
468
- }
469
- });
470
- }
471
- function templatizeWidgets(itemTemplate, authentication, portalUrl, widgetPath, isOnScreen) {
472
- if (isOnScreen === void 0) { isOnScreen = false; }
473
- return new Promise(function (resolve, reject) {
474
- // update widgets
475
- var widgets = common.getProp(itemTemplate, widgetPath) || [];
476
- var serviceRequests = [];
477
- var requestUrls = [];
478
- widgets.forEach(function (widget) {
479
- /* istanbul ignore else */
480
- if (!isOnScreen && common.getProp(widget, "icon")) {
481
- setValues(widget, ["icon"], common.placeholder(common.SERVER_NAME));
482
- }
483
- var config = widget.config;
484
- if (config) {
485
- var sConfig = JSON.stringify(config);
486
- var urlResults = findUrls(sConfig, portalUrl, requestUrls, serviceRequests, authentication);
487
- widget.config = JSON.parse(urlResults.testString);
488
- serviceRequests = urlResults.serviceRequests;
489
- requestUrls = urlResults.requestUrls;
490
- }
491
- });
492
- if (serviceRequests.length > 0) {
493
- var sWidgets = JSON.stringify(widgets);
494
- handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(function (response) {
495
- common.setProp(itemTemplate, widgetPath, JSON.parse(response));
496
- resolve(itemTemplate);
497
- }, function (e) { return reject(common.fail(e)); });
498
- }
499
- else {
500
- resolve(itemTemplate);
501
- }
502
- });
503
- }
504
- function templatizeValues(itemTemplate, authentication, portalUrl, widgetPath) {
505
- return new Promise(function (resolve, reject) {
506
- // update properties of values collection for web app templates
507
- var values = common.getProp(itemTemplate, widgetPath);
508
- var serviceRequests = [];
509
- var requestUrls = [];
510
- if (values) {
511
- if (common.getProp(values, "icon")) {
512
- setValues(values, ["icon"], common.placeholder(common.SERVER_NAME));
513
- }
514
- var sConfig = JSON.stringify(values);
515
- var urlResults = findUrls(sConfig, portalUrl, requestUrls, serviceRequests, authentication);
516
- values = JSON.parse(urlResults.testString);
517
- serviceRequests = urlResults.serviceRequests;
518
- requestUrls = urlResults.requestUrls;
519
- }
520
- if (serviceRequests.length > 0) {
521
- var sWidgets = JSON.stringify(values);
522
- handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(function (response) {
523
- common.setProp(itemTemplate, widgetPath, JSON.parse(response));
524
- resolve(itemTemplate);
525
- }, function (e) { return reject(common.fail(e)); });
526
- }
527
- else {
528
- resolve(itemTemplate);
529
- }
530
- });
531
- }
532
- function handleServiceRequests(serviceRequests, requestUrls, objString) {
533
- return new Promise(function (resolve, reject) {
534
- if (serviceRequests && serviceRequests.length > 0) {
535
- var i_1 = 0;
536
- Promise.all(serviceRequests).then(function (serviceResponses) {
537
- serviceResponses.forEach(function (serviceResponse) {
538
- if (common.getProp(serviceResponse, "serviceItemId")) {
539
- var serviceTemplate = "{{" +
540
- serviceResponse.serviceItemId +
541
- (serviceResponse.hasOwnProperty("id")
542
- ? ".layer" + serviceResponse.id
543
- : "") +
544
- ".url}}";
545
- objString = replaceUrl(objString, requestUrls[i_1], serviceTemplate, true);
546
- }
547
- i_1++;
548
- });
549
- resolve(objString);
550
- }, function (e) { return reject(common.fail(e)); });
551
- }
552
- else {
553
- resolve(objString);
554
- }
555
- });
556
- }
557
- function findUrls(testString, portalUrl, requestUrls, serviceRequests, authentication) {
558
- var options = {
559
- f: "json",
560
- authentication: authentication
561
- };
562
- // test for URLs
563
- var results = testString.match(/(\bhttps?:\/\/[-A-Z0-9/._]*)/gim);
564
- if (results && results.length) {
565
- results.forEach(function (url) {
566
- if (url.indexOf("NAServer") > -1) {
567
- testString = replaceUrl(testString, url, common.placeholder(common.NA_SERVER_NAME));
568
- }
569
- else if (url.indexOf("GeocodeServer") > -1) {
570
- testString = replaceUrl(testString, url, common.placeholder(common.GEOCODE_SERVER_NAME));
571
- }
572
- else if (portalUrl && url.indexOf(portalUrl) > -1) {
573
- testString = replaceUrl(testString, portalUrl, common.placeholder(common.SERVER_NAME));
574
- }
575
- else if (url.indexOf("FeatureServer") > -1) {
576
- if (requestUrls.indexOf(url) === -1) {
577
- requestUrls.push(url);
578
- serviceRequests.push(common.rest_request(url, options));
579
- }
580
- }
581
- });
582
- }
583
- return {
584
- testString: testString,
585
- requestUrls: requestUrls,
586
- serviceRequests: serviceRequests
587
- };
588
- }
589
- /**
590
- * Replace url with templatized url value
591
- *
592
- * @param obj can be a single url string or a stringified JSON object
593
- * @param url the current url we are testing for
594
- * @param newUrl the templatized url
595
- * @param validateFullUrl should only replace url when we have a full match.
596
- * This property is only relevant when the obj is a stringified JSON object.
597
- *
598
- * @returns the obj with any instances of the url replaced
599
- */
600
- function replaceUrl(obj, url, newUrl, validateFullUrl) {
601
- if (validateFullUrl === void 0) { validateFullUrl = false; }
602
- var enforceFullUrl = validateFullUrl && obj.indexOf('"') > -1;
603
- var re = new RegExp(enforceFullUrl ? '"' + url + '"' : url, "gmi");
604
- return obj.replace(re, enforceFullUrl ? '"' + newUrl + '"' : newUrl);
605
- }
606
- function setValues(itemTemplate, paths, base) {
607
- paths.forEach(function (path) {
608
- var url = common.getProp(itemTemplate, path);
609
- if (url) {
610
- var subString = url.substring(url.indexOf("/", url.indexOf("//") + 2));
611
- common.setProp(itemTemplate, path, subString !== url ? base + subString : base);
612
- }
613
- });
614
- }
615
- function fineTuneCreatedItem(originalTemplate, newlyCreatedItem, templateDictionary, destinationAuthentication) {
616
- return new Promise(function (resolve) {
617
- // If this is a Web AppBuilder application, we will create a Code Attachment for downloading
618
- if (common.hasAnyKeyword(originalTemplate, [
619
- "WAB2D",
620
- "WAB3D",
621
- "Web AppBuilder"
622
- ])) {
623
- // Update item so properties like appItemId can now be set now that we know the new apps ID
624
- var updateOptions = {
625
- id: newlyCreatedItem.itemId,
626
- url: newlyCreatedItem.item.url,
627
- data: newlyCreatedItem.data
628
- };
629
- var updateDef = common.updateItem(updateOptions, destinationAuthentication);
630
- var itemInfo = {
631
- tags: originalTemplate.item.tags,
632
- title: originalTemplate.item.title,
633
- type: "Code Attachment",
634
- typeKeywords: ["Code", "Javascript", "Web Mapping Application"],
635
- relationshipType: "WMA2Code",
636
- originItemId: newlyCreatedItem.itemId,
637
- url: common.checkUrlPathTermination(common.replaceInTemplate(common.placeholder(common.SERVER_NAME), templateDictionary)) +
638
- "sharing/rest/content/items/" +
639
- newlyCreatedItem.itemId +
640
- "/package"
641
- };
642
- var createItemWithDataDef = common.createItemWithData(itemInfo, {}, destinationAuthentication, templateDictionary.folderId);
643
- Promise.all([updateDef, createItemWithDataDef]).then(function () { return resolve(null); }, function () { return resolve(null); });
644
- }
645
- else {
646
- // Otherwise, nothing extra needed
647
- resolve(null);
648
- }
649
- });
650
- }
651
- // ------------------------------------------------------------------------------------------------------------------ //
652
- /**
653
- * Gets the ids of the dependencies of an AGOL webapp item.
654
- *
655
- * @param fullItem A webapp item whose dependencies are sought
656
- * @return A promise that will resolve with list of dependent ids
657
- * @protected
658
- */
659
- function _extractDependencies$1(model) {
660
- var processor = _getGenericWebAppDependencies;
661
- /*
662
- if (common.hasTypeKeyword(model, "Story Map")) {
663
- processor = getStoryMapDependencies;
664
- }
665
- */
666
- if (common.hasAnyKeyword(model, ["WAB2D", "WAB3D", "Web AppBuilder"])) {
667
- processor = _getWABDependencies;
668
- }
669
- return processor(model);
670
- }
671
- /**
672
- * Generic Web App Dependencies
673
- */
674
- function _getGenericWebAppDependencies(model) {
675
- var props = ["data.values.webmap", "data.values.group"];
676
- return common.getProps(model, props);
677
- }
678
- function _getWABDependencies(model) {
679
- var deps = [];
680
- var v = common.getProp(model, "data.map.itemId");
681
- if (v) {
682
- deps.push(v);
683
- }
684
- var dataSources = common.getProp(model, "data.dataSource.dataSources");
685
- if (dataSources) {
686
- Object.keys(dataSources).forEach(function (k) {
687
- var ds = dataSources[k];
688
- if (ds.itemId) {
689
- deps.push(ds.itemId);
690
- }
691
- });
692
- }
693
- return deps;
694
- }
695
- /**
696
- * Templatizes id properties for the paths provided
697
- *
698
- * @param itemTemplate The solution item template
699
- * @param paths A list of property paths that contain ids
700
- * @protected
701
- */
702
- function _templatizeIdPaths(itemTemplate, paths) {
703
- paths.forEach(function (path) {
704
- var id = common.getProp(itemTemplate, path);
705
- _templatizeIdPath(itemTemplate, path, id);
706
- });
707
- }
708
- /**
709
- * Templatizes id property for the path provided
710
- *
711
- * @param itemTemplate The solution item template
712
- * @param path A path to an id property
713
- * @param id The base id to use when templatizing
714
- * @protected
715
- */
716
- function _templatizeIdPath(itemTemplate, path, id) {
717
- common.setProp(itemTemplate, path, common.templatizeTerm(id, id, ".itemId"));
718
- }
719
- /**
720
- * Templatize field references for datasources and widgets.
721
- *
722
- * @param solutionTemplate The solution item template
723
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
724
- * @returns The solutionTemplate with templatized field references
725
- */
726
- function postProcessFieldReferences$1(solutionTemplate, datasourceInfos) {
727
- // handle datasources common for WAB apps
728
- var dataSources = common.getProp(solutionTemplate, "data.dataSource.dataSources");
729
- if (dataSources && Object.keys(dataSources).length > 0) {
730
- Object.keys(dataSources).forEach(function (k) {
731
- var ds = dataSources[k];
732
- dataSources[k] = _templatizeObject(ds, datasourceInfos);
733
- });
734
- common.setProp(solutionTemplate, "data.dataSource.dataSources", dataSources);
735
- }
736
- // handle widgets common for WAB apps
737
- var paths = [
738
- "data.widgetPool.widgets",
739
- "data.widgetOnScreen.widgets"
740
- ];
741
- paths.forEach(function (path) {
742
- var widgets = common.getProp(solutionTemplate, path);
743
- if (widgets) {
744
- common.setProp(solutionTemplate, path, _templatizeObjectArray(widgets, datasourceInfos));
745
- }
746
- });
747
- // handle values common for web app templates
748
- var values = common.getProp(solutionTemplate, "data.values");
749
- if (values) {
750
- common.setProp(solutionTemplate, "data.values", _templatizeObject(values, datasourceInfos));
751
- }
752
- return solutionTemplate;
753
- }
754
- /**
755
- * Templatize field references for given dataSource from the web application.
756
- *
757
- * @param obj The dataSource or widget object from the web application.
758
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
759
- * @returns The dataSource with templatized field references
760
- */
761
- function _templatizeObject(obj, datasourceInfos, templatizeKeys) {
762
- if (templatizeKeys === void 0) { templatizeKeys = false; }
763
- obj = _prioritizedTests(obj, datasourceInfos, templatizeKeys);
764
- var replaceOrder = _getReplaceOrder(obj, datasourceInfos);
765
- replaceOrder.forEach(function (ds) {
766
- obj = common.templatizeFieldReferences(obj, ds.fields, ds.basePath, templatizeKeys);
767
- });
768
- return obj;
769
- }
770
- /**
771
- * Templatize field references from an array of various objects from the web application.
772
- *
773
- * @param objects A list of widgets or objects from the web application that may contain field references.
774
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
775
- * @returns The widgets with templatized field references
776
- */
777
- function _templatizeObjectArray(objects, datasourceInfos) {
778
- var updateKeyObjects = ["SmartEditor", "Screening"];
779
- return objects.map(function (obj) {
780
- // only templatize the config and lower
781
- if (obj.config) {
782
- var templatizeKeys = updateKeyObjects.indexOf(obj.name) > -1;
783
- obj.config = _templatizeObject(obj.config, datasourceInfos, templatizeKeys);
784
- }
785
- return obj;
786
- });
787
- }
788
- /**
789
- * Gets an order for testing wit the various datasource info objects against the widget or dataSource.
790
- * A widget or dataSource that contain a layers url or webmap layer id are more likely
791
- * to have field references from that layer.
792
- *
793
- * @param obj The dataSource or widget object from the web application.
794
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
795
- * @returns A list of datasourceInfo objects sorted based on the presence of a layers url or id
796
- */
797
- function _getReplaceOrder(obj, datasourceInfos) {
798
- var objString = JSON.stringify(obj);
799
- // If we don't find any layer url, web map layer id, service url, agol itemId then remove the datasource.
800
- var _datasourceInfos = datasourceInfos.filter(function (ds) { return _getSortOrder(ds, objString) < 4; });
801
- return _datasourceInfos.sort(function (a, b) {
802
- return _getSortOrder(a, objString) - _getSortOrder(b, objString);
803
- });
804
- }
805
- /**
806
- * Determine an order for checking field names against a dataSource or widget.
807
- * Sort order preference is set in this order: layer url, web map layer id, service url, agol itemId
808
- *
809
- * @param datasourceInfo The datasource object with key properties about the service.
810
- * @param testString A stringified version of a widget or dataSource
811
- * @returns The prioritized order for testing
812
- */
813
- function _getSortOrder(datasourceInfo, testString) {
814
- var url = datasourceInfo.url;
815
- var itemId = datasourceInfo.itemId;
816
- var layerId = datasourceInfo.layerId;
817
- // if we have the url and the layerID and its found prioritize it first
818
- // else if we find the maps layer id prioritze it first
819
- var layerUrlTest;
820
- if (url && !isNaN(layerId)) {
821
- layerUrlTest = new RegExp(url.replace(/[.]/, ".layer" + layerId + "."), "gm");
822
- }
823
- if (layerUrlTest && layerUrlTest.test(testString)) {
824
- return 1;
825
- }
826
- else if (datasourceInfo.ids.length > 0) {
827
- if (datasourceInfo.ids.some(function (id) {
828
- var layerMapIdTest = new RegExp(id, "gm");
829
- return layerMapIdTest.test(testString);
830
- })) {
831
- return 1;
832
- }
833
- }
834
- // if neither full layer url or map layer id are found...check to see if we can
835
- // find the base service url
836
- if (url) {
837
- var serviceUrlTest = new RegExp(url, "gm");
838
- if (serviceUrlTest.test(testString)) {
839
- return 2;
840
- }
841
- }
842
- // if none of the above see if we can find an AGOL item id reference
843
- if (itemId) {
844
- var itemIdTest = new RegExp(itemId, "gm");
845
- if (itemIdTest.test(testString)) {
846
- return 3;
847
- }
848
- }
849
- return 4;
850
- }
851
- /**
852
- * These tests will run prior to the tests associated with the higher level tests based on sort order.
853
- * The tests work more like cloning an object where we go through and review each individual property.
854
- * If we find a url or webmap layer id we will templatize the parent object that contains this property.
855
- * Many widgets will store one of these two properties in an object that will also contain various field references.
856
- *
857
- * @param obj The dataSource or widget object from the application
858
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
859
- * @returns An updated instance of the dataSource or widget with as many field references templatized as possible.
860
- */
861
- function _prioritizedTests(obj, datasourceInfos, templatizeKeys) {
862
- var objString = JSON.stringify(obj);
863
- var hasDatasources = datasourceInfos.filter(function (ds) {
864
- var urlTest;
865
- if (ds.url && !isNaN(ds.layerId)) {
866
- urlTest = new RegExp(ds.url.replace(/[.]/, ".layer" + ds.layerId + "."), "gm");
867
- }
868
- var hasMapLayerId = false;
869
- if (ds.ids.length > 0) {
870
- hasMapLayerId = ds.ids.some(function (id) {
871
- var idTest = new RegExp(id, "gm");
872
- return idTest.test(objString);
873
- });
874
- }
875
- if (hasMapLayerId || (urlTest && urlTest.test(objString))) {
876
- return ds;
877
- }
878
- });
879
- if (hasDatasources.length > 0) {
880
- hasDatasources.forEach(function (ds) {
881
- // specific url reference is the most common
882
- obj = _templatizeParentByURL(obj, ds, templatizeKeys);
883
- if (ds.ids.length > 0) {
884
- // the second most common is to use the layerId from the webmap
885
- ds.ids.forEach(function (id) {
886
- obj = _templatizeParentByWebMapLayerId(obj, ds, id, templatizeKeys);
887
- });
888
- }
889
- });
890
- }
891
- return obj;
892
- }
893
- /**
894
- * This is very close to common.cloneObject but will test if an object
895
- * has one of the datasource urls as a property. If it finds one it will
896
- * templatize it's parent based on the fields from that datasource
897
- *
898
- * @param obj The dataSource or widget object from the application
899
- * @param ds A datasourceInfo object to use for testing against the current dataSource or widget
900
- * @returns The updated instance of the object with as many field references templatized as possible
901
- */
902
- function _templatizeParentByURL(obj, ds, templatizeKeys) {
903
- var clone = {};
904
- var url = ds.url;
905
- var layerId = ds.layerId;
906
- var urlTest;
907
- if (url && !isNaN(layerId)) {
908
- urlTest = new RegExp(url.replace(/[.]/, ".layer" + layerId + "."), "gm");
909
- }
910
- if (Array.isArray(obj)) {
911
- clone = obj.map(function (c) {
912
- return _templatizeParentByURL(c, ds, templatizeKeys);
913
- });
914
- }
915
- else if (typeof obj === "object") {
916
- for (var i in obj) {
917
- if (obj[i] != null && typeof obj[i] === "object") {
918
- clone[i] = _templatizeParentByURL(obj[i], ds, templatizeKeys);
919
- }
920
- else {
921
- if (urlTest && urlTest.test(obj[i])) {
922
- obj = common.templatizeFieldReferences(obj, ds.fields, ds.basePath, templatizeKeys);
923
- }
924
- clone[i] = obj[i];
925
- }
926
- }
927
- }
928
- else {
929
- clone = obj;
930
- }
931
- return clone;
932
- }
933
- /**
934
- * This is very close to common.cloneObject but will test if an object
935
- * has one of the datasource webmap layer ids as a property. If it finds one it will
936
- * templatize it's parent based on the fields from that datasource.
937
- *
938
- * @param obj The dataSource or widget object from the application
939
- * @param ds A datasourceInfo object to use for testing against the current dataSource or widget
940
- * @param id A webmap layer id to test with.
941
- * @returns The updated instance of the object with as many field references templatized as possible
942
- */
943
- function _templatizeParentByWebMapLayerId(obj, ds, id, templatizeKeys) {
944
- var clone = {};
945
- var idTest = new RegExp(id, "gm");
946
- if (Array.isArray(obj)) {
947
- clone = obj.map(function (c) {
948
- return _templatizeParentByWebMapLayerId(c, ds, id, templatizeKeys);
949
- });
950
- }
951
- else if (typeof obj === "object") {
952
- for (var i in obj) {
953
- if (obj[i] !== null) {
954
- // In some web application templates they store a stringified version of an object that can
955
- // contain multiple layer references at a very high level on the main values collection.
956
- // This was causing many other more typical layer references to be set incorrectly as the first
957
- // layerId found in this high level string would be used against the main object.
958
- var parsedProp = void 0;
959
- try {
960
- parsedProp = JSON.parse(obj[i]);
961
- }
962
- catch (error) {
963
- parsedProp = undefined;
964
- }
965
- if (parsedProp && typeof parsedProp === "object") {
966
- clone[i] = JSON.stringify(_templatizeParentByWebMapLayerId(parsedProp, ds, id, templatizeKeys));
967
- }
968
- else if (typeof obj[i] === "object") {
969
- // some widgets store the layerId as a key to a collection of details that contain field references
970
- if (idTest.test(i) && templatizeKeys) {
971
- obj[i] = common.templatizeFieldReferences(obj[i], ds.fields, ds.basePath, templatizeKeys);
972
- }
973
- clone[i] = _templatizeParentByWebMapLayerId(obj[i], ds, id, templatizeKeys);
974
- }
975
- else {
976
- if (idTest.test(obj[i])) {
977
- obj = common.templatizeFieldReferences(obj, ds.fields, ds.basePath, templatizeKeys);
978
- }
979
- clone[i] = obj[i];
980
- }
981
- }
982
- else {
983
- clone[i] = obj[i];
984
- }
985
- }
986
- }
987
- else {
988
- clone = obj;
989
- }
990
- return clone;
991
- }
44
+ /** @license
45
+ * Copyright 2018 Esri
46
+ *
47
+ * Licensed under the Apache License, Version 2.0 (the "License");
48
+ * you may not use this file except in compliance with the License.
49
+ * You may obtain a copy of the License at
50
+ *
51
+ * http://www.apache.org/licenses/LICENSE-2.0
52
+ *
53
+ * Unless required by applicable law or agreed to in writing, software
54
+ * distributed under the License is distributed on an "AS IS" BASIS,
55
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
56
+ * See the License for the specific language governing permissions and
57
+ * limitations under the License.
58
+ */
59
+ /**
60
+ * Converts a dashboard item to a template.
61
+ *
62
+ * @param itemTemplate Template for the dashboard item
63
+ * @return templatized itemTemplate
64
+ */
65
+ function convertItemToTemplate$8(itemTemplate) {
66
+ return _extractDependencies$3(itemTemplate);
67
+ }
68
+ /**
69
+ * Templatizes all itemIds and updates the dependency array
70
+ *
71
+ * @param itemTemplate Template for the dashboard item
72
+ * @return The updated itemTemplate
73
+ * @protected
74
+ */
75
+ function _extractDependencies$3(itemTemplate) {
76
+ // get dependencies from any
77
+ const updatePaths = [
78
+ "data.widgets",
79
+ "data.headerPanel.selectors",
80
+ "data.leftPanel.selectors",
81
+ "data.urlParameters"
82
+ ];
83
+ updatePaths.forEach(path => {
84
+ const objs = common__namespace.getProp(itemTemplate, path);
85
+ if (Array.isArray(objs)) {
86
+ objs.forEach(obj => {
87
+ /* istanbul ignore else */
88
+ if (obj.type === "mapWidget") {
89
+ /* istanbul ignore else */
90
+ if (itemTemplate.dependencies.indexOf(obj.itemId) < 0) {
91
+ itemTemplate.dependencies.push(obj.itemId);
92
+ }
93
+ obj.itemId = common__namespace.templatizeTerm(obj.itemId, obj.itemId, ".itemId");
94
+ }
95
+ /* istanbul ignore else */
96
+ if (Array.isArray(obj.datasets)) {
97
+ _getDatasourceDependencies(obj, itemTemplate);
98
+ }
99
+ });
100
+ }
101
+ });
102
+ return itemTemplate;
103
+ }
104
+ /**
105
+ * Templatize datasource itemIds and update the dependency array
106
+ *
107
+ * @param obj A widget, selector, or urlParameter that contains a datasets collection
108
+ * @param itemTemplate Template for the dashboard item
109
+ */
110
+ function _getDatasourceDependencies(obj, itemTemplate) {
111
+ obj.datasets.forEach((dataset) => {
112
+ // when the datasource has an itemId is an external datasource
113
+ const itemId = common__namespace.getProp(dataset, "dataSource.itemId");
114
+ if (itemId) {
115
+ if (itemTemplate.dependencies.indexOf(itemId) < 0) {
116
+ itemTemplate.dependencies.push(itemId);
117
+ }
118
+ const layerId = common__namespace.getProp(dataset, "dataSource.layerId");
119
+ dataset.dataSource.itemId = common__namespace.templatizeTerm(itemId, itemId, layerId !== undefined ? ".layer" + layerId + ".itemId" : ".itemId");
120
+ /* istanbul ignore else */
121
+ if (layerId !== undefined) {
122
+ dataset.dataSource.layerId = common__namespace.templatizeTerm(itemId, itemId, ".layer" + layerId + ".layerId");
123
+ }
124
+ }
125
+ });
126
+ }
127
+ /**
128
+ * Templatize field references for datasources and widgets.
129
+ *
130
+ * @param solutionTemplate The solution item template
131
+ * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
132
+ * @returns The solutionTemplate with templatized field references
133
+ */
134
+ function postProcessFieldReferences$3(solutionTemplate, datasourceInfos) {
135
+ const updatePaths = [
136
+ "data.widgets",
137
+ "data.headerPanel.selectors",
138
+ "data.leftPanel.selectors",
139
+ "data.urlParameters"
140
+ ];
141
+ // dashboards reference datasets from other widgets
142
+ // add reference IDs to the appropriate datasourceInfos
143
+ updatePaths.forEach(path => {
144
+ const objs = common__namespace.getProp(solutionTemplate, path);
145
+ _updateDatasourceReferences(objs, datasourceInfos);
146
+ });
147
+ // after we know the potential references go ahead and templatize
148
+ updatePaths.forEach(path => {
149
+ _templatize$1(solutionTemplate, path, datasourceInfos);
150
+ });
151
+ return solutionTemplate;
152
+ }
153
+ /**
154
+ * Add all dataset ids to the appropriate datasource info object so we can navigate any relative references
155
+ *
156
+ * @param objs Thes can be widgets, selectors, or urlParameters
157
+ * @param datasourceInfos A list of objects that contain key details about the datasources from the application
158
+ * @protected
159
+ */
160
+ function _updateDatasourceReferences(objs, datasourceInfos) {
161
+ // objects can be events or widgets
162
+ /* istanbul ignore else */
163
+ if (objs && Array.isArray(objs)) {
164
+ objs.forEach(obj => {
165
+ if (Array.isArray(obj.datasets)) {
166
+ obj.datasets.forEach((dataset) => {
167
+ // when the datasource has an itemId it's an external datasource
168
+ const itemId = common__namespace.cleanLayerBasedItemId(common__namespace.getProp(dataset, "dataSource.itemId"));
169
+ if (itemId) {
170
+ const layerId = common__namespace.cleanLayerId(common__namespace.getProp(dataset, "dataSource.layerId"));
171
+ datasourceInfos.some(ds => {
172
+ if (ds.itemId === itemId && ds.layerId === layerId) {
173
+ _updateReferences(ds, obj.id);
174
+ return true;
175
+ }
176
+ else {
177
+ return false;
178
+ }
179
+ });
180
+ }
181
+ else {
182
+ // add placeholder for map layer datasource info so we can know the items that reference them
183
+ // needed when item field reference are derived from another widgets datasource eg. <dashboardWidgetId>#datasetname
184
+ const id = common__namespace.getProp(dataset, "dataSource.id");
185
+ if (id) {
186
+ const dashboardLayerId = id.split("#")[1];
187
+ datasourceInfos.some(ds => {
188
+ if (ds.ids.indexOf(dashboardLayerId) > -1) {
189
+ _updateReferences(ds, obj.id);
190
+ return true;
191
+ }
192
+ else {
193
+ return false;
194
+ }
195
+ });
196
+ }
197
+ }
198
+ });
199
+ }
200
+ });
201
+ }
202
+ }
203
+ /**
204
+ * Templatize all datasets and/or events for the objects at the given path
205
+ *
206
+ * @param itemTemplate Template for the dashboard item
207
+ * @param path A property path to an array of objects that could contain datasets or events
208
+ * @param datasourceInfos A list of objects that contain key details about the datasources from the application
209
+ * @protected
210
+ */
211
+ function _templatize$1(itemTemplate, path, datasourceInfos) {
212
+ const obj = common__namespace.getProp(itemTemplate, path);
213
+ /* istanbul ignore else */
214
+ if (obj) {
215
+ common__namespace.setProp(itemTemplate, path, _templatizeByDatasource(obj, datasourceInfos));
216
+ }
217
+ }
218
+ /**
219
+ * For any service dataset datasource templatize all field references
220
+ *
221
+ * @param objs A list of objects that can contain field references
222
+ * @param datasourceInfos A list of objects that contain key details about the datasources from the application
223
+ * @return An updated list of objects with templatized field references
224
+ * @protected
225
+ */
226
+ function _templatizeByDatasource(objs, datasourceInfos) {
227
+ if (Array.isArray(objs)) {
228
+ return objs.map(obj => {
229
+ let _obj = obj;
230
+ if (Array.isArray(_obj.events)) {
231
+ // Events can be associated with datasets but they can also be associated with a target
232
+ // In some cases an event will have a source and a target.
233
+ // Handle these specifically first to ensure that it has the correct layer reference
234
+ _obj.events = _obj.events.map((event) => {
235
+ const _event = event;
236
+ /* istanbul ignore else */
237
+ if (Array.isArray(_event.actions)) {
238
+ _event.actions = _event.actions.map((action) => {
239
+ const _action = action;
240
+ if (_action.fieldMap &&
241
+ _action.targetId &&
242
+ _action.targetId.indexOf("#") > -1) {
243
+ const datasourceInfo = _getDatasourceInfo$1(_action, datasourceInfos);
244
+ /* istanbul ignore else */
245
+ if (datasourceInfo) {
246
+ const fields = common__namespace.getProp(datasourceInfo, "fields");
247
+ const basePath = common__namespace.getProp(datasourceInfo, "basePath");
248
+ /* istanbul ignore else */
249
+ if (Array.isArray(fields) && basePath) {
250
+ _action.fieldMap = _action.fieldMap.map((m) => {
251
+ const _m = m;
252
+ _m.targetName = common__namespace.templatizeFieldReferences(_m.targetName, fields, basePath);
253
+ return _m;
254
+ });
255
+ }
256
+ }
257
+ }
258
+ return _action;
259
+ });
260
+ }
261
+ return _event;
262
+ });
263
+ }
264
+ if (Array.isArray(_obj.datasets)) {
265
+ _obj.datasets = _obj.datasets.map((dataset) => {
266
+ let _dataset = dataset;
267
+ if (_dataset.type === "serviceDataset") {
268
+ const datasourceInfo = _getDatasourceInfo$1(dataset, datasourceInfos);
269
+ /* istanbul ignore else */
270
+ if (datasourceInfo) {
271
+ const fields = common__namespace.getProp(datasourceInfo, "fields");
272
+ const basePath = common__namespace.getProp(datasourceInfo, "basePath");
273
+ /* istanbul ignore else */
274
+ if (Array.isArray(fields) && basePath) {
275
+ _obj = common__namespace.templatizeFieldReferences(_obj, fields, basePath);
276
+ _dataset = common__namespace.templatizeFieldReferences(_dataset, fields, basePath);
277
+ }
278
+ }
279
+ }
280
+ return _dataset;
281
+ });
282
+ return _obj;
283
+ }
284
+ else
285
+ return _obj;
286
+ });
287
+ }
288
+ else {
289
+ return objs;
290
+ }
291
+ }
292
+ /**
293
+ * Find the appropriate datasource info object from the datasourceInfo collection
294
+ *
295
+ * @param obj Can be a Dataset or an event
296
+ * @param datasourceInfos A list of objects that contain key details about the datasources from the application
297
+ * @return The supporting datasource info for the given object
298
+ * @protected
299
+ */
300
+ function _getDatasourceInfo$1(obj, datasourceInfos) {
301
+ let info;
302
+ // the datasource will have an id property when it's referencing a map layer
303
+ // the fields collection will already be defined
304
+ const id = common__namespace.getProp(obj, "dataSource.id") || common__namespace.getProp(obj, "targetId");
305
+ if (id) {
306
+ const dashboardLayerId = id.split("#")[1];
307
+ if (!datasourceInfos.some(di => {
308
+ info = di.ids.indexOf(dashboardLayerId) > -1 ? di : info;
309
+ return di.ids.indexOf(dashboardLayerId) > -1;
310
+ })) {
311
+ // in some cases the id will not contain a layer name...it will have the dashboard id for another widget
312
+ // in that case lookup the datasource from referenced widget
313
+ const dashboardWidgetId = id.split("#")[0];
314
+ datasourceInfos.some(di => {
315
+ const references = di.references || [];
316
+ const hasRef = references.indexOf(dashboardWidgetId) > -1;
317
+ info = hasRef ? di : info;
318
+ return hasRef;
319
+ });
320
+ }
321
+ }
322
+ else {
323
+ // otherwise match the itemId and the layerId to get the correct fields and path
324
+ const itemId = common__namespace.cleanLayerBasedItemId(common__namespace.getProp(obj, "dataSource.itemId"));
325
+ const layerId = common__namespace.cleanLayerId(common__namespace.getProp(obj, "dataSource.layerId"));
326
+ /* istanbul ignore else */
327
+ if (itemId) {
328
+ datasourceInfos.some(di => {
329
+ const matches = itemId === di.itemId && layerId === di.layerId;
330
+ info = matches ? di : info;
331
+ return matches;
332
+ });
333
+ }
334
+ }
335
+ return info;
336
+ }
337
+ /**
338
+ * Verifies if the datasource info contains the given id and adds it if not
339
+ *
340
+ * @param ds The datasource info to add the reference to
341
+ * @param id The id from dashboard object, commonly another widget
342
+ * @protected
343
+ */
344
+ function _updateReferences(ds, id) {
345
+ ds.references = Array.isArray(ds.references) ? ds.references : [];
346
+ if (ds.references.indexOf(id) < 0) {
347
+ ds.references.push(id);
348
+ }
349
+ }
992
350
 
993
- /** @license
994
- * Copyright 2018 Esri
995
- *
996
- * Licensed under the Apache License, Version 2.0 (the "License");
997
- * you may not use this file except in compliance with the License.
998
- * You may obtain a copy of the License at
999
- *
1000
- * http://www.apache.org/licenses/LICENSE-2.0
1001
- *
1002
- * Unless required by applicable law or agreed to in writing, software
1003
- * distributed under the License is distributed on an "AS IS" BASIS,
1004
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1005
- * See the License for the specific language governing permissions and
1006
- * limitations under the License.
1007
- */
1008
- /**
1009
- * Converts an workforce item to a template.
1010
- *
1011
- * @param itemTemplate template for the workforce project item
1012
- * @param authentication credentials for any requests
1013
- * @return templatized itemTemplate
1014
- */
1015
- function convertItemToTemplate$2(itemTemplate, authentication) {
1016
- return common.convertWorkforceItemToTemplate(itemTemplate, authentication);
1017
- }
1018
- /**
1019
- * Gets the current user and updates the dispatchers service
1020
- *
1021
- * @param newlyCreatedItem Item to be created; n.b.: this item is modified
1022
- * @param destinationAuthentication The session used to create the new item(s)
1023
- * @return A promise that will resolve with { "success" === true || false }
1024
- */
1025
- function fineTuneCreatedItem$1(newlyCreatedItem, destinationAuthentication, templateDictionary) {
1026
- return common.fineTuneCreatedWorkforceItem(newlyCreatedItem, destinationAuthentication, "", templateDictionary);
1027
- }
351
+ /** @license
352
+ * Copyright 2020 Esri
353
+ *
354
+ * Licensed under the Apache License, Version 2.0 (the "License");
355
+ * you may not use this file except in compliance with the License.
356
+ * You may obtain a copy of the License at
357
+ *
358
+ * http://www.apache.org/licenses/LICENSE-2.0
359
+ *
360
+ * Unless required by applicable law or agreed to in writing, software
361
+ * distributed under the License is distributed on an "AS IS" BASIS,
362
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
363
+ * See the License for the specific language governing permissions and
364
+ * limitations under the License.
365
+ */
366
+ // ------------------------------------------------------------------------------------------------------------------ //
367
+ /**
368
+ * Converts a web mapping application item into a template.
369
+ *
370
+ * @param itemInfo Info about the item
371
+ * @param destAuthentication Credentials for requests to the destination organization
372
+ * @param srcAuthentication Credentials for requests to source items
373
+ * @return A promise that will resolve when the template has been created
374
+ */
375
+ function convertItemToTemplate$7(itemTemplate, destAuthentication, srcAuthentication) {
376
+ return new Promise((resolve, reject) => {
377
+ // Remove org base URL and app id, e.g.,
378
+ // http://anOrg.maps.arcgis.com/apps/CrowdsourcePolling/index.html?appid=6fc5992522d34a6b5ce80d17835eea21
379
+ // to
380
+ // <placeholder(SERVER_NAME)>/apps/CrowdsourcePolling/index.html?appid={{<itemId>.id}}
381
+ // Need to add placeholder server name because otherwise AGOL makes URL null
382
+ let portalUrl = "";
383
+ if (itemTemplate.item.url) {
384
+ const templatizedUrl = itemTemplate.item.url;
385
+ const iSep = templatizedUrl.indexOf("//");
386
+ itemTemplate.item.url =
387
+ common__namespace.placeholder(common__namespace.SERVER_NAME) + // add placeholder server name
388
+ templatizedUrl.substring(templatizedUrl.indexOf("/", iSep + 2), templatizedUrl.lastIndexOf("=") + 1) +
389
+ itemTemplate.item.id; // templatized id
390
+ portalUrl = templatizedUrl.replace(templatizedUrl.substring(templatizedUrl.indexOf("/", iSep + 2)), "");
391
+ }
392
+ // Extract dependencies
393
+ itemTemplate.dependencies = _extractDependencies$2(itemTemplate);
394
+ // Set the folder
395
+ common__namespace.setProp(itemTemplate, "data.folderId", "{{folderId}}");
396
+ // Set the map or group after we've extracted them as dependencies
397
+ _templatizeIdPaths(itemTemplate, [
398
+ "data.map.itemId",
399
+ "data.map.appProxy.mapItemId",
400
+ "data.values.webmap",
401
+ "data.values.group"
402
+ ]);
403
+ // force the appItemId to be pulled directly from the template item
404
+ // this is to address solution.js #124
405
+ _templatizeIdPath(itemTemplate, "data.appItemId", itemTemplate.itemId);
406
+ setValues(itemTemplate, [
407
+ "data.logo",
408
+ "data.map.portalUrl",
409
+ "data.portalUrl",
410
+ "data.httpProxy.url"
411
+ ], common__namespace.placeholder(common__namespace.SERVER_NAME));
412
+ common__namespace.setProp(itemTemplate, "data.geometryService", common__namespace.placeholder(common__namespace.GEOMETRY_SERVER_NAME));
413
+ templatizeDatasources(itemTemplate, srcAuthentication, portalUrl).then(() => {
414
+ templatizeWidgets(itemTemplate, srcAuthentication, portalUrl, "data.widgetPool.widgets").then(_itemTemplate => {
415
+ templatizeWidgets(_itemTemplate, srcAuthentication, portalUrl, "data.widgetOnScreen.widgets", true).then(updatedItemTemplate => {
416
+ templatizeValues(updatedItemTemplate, srcAuthentication, portalUrl, "data.values").then(_updatedItemTemplate => {
417
+ resolve(_updatedItemTemplate);
418
+ }, e => reject(common__namespace.fail(e)));
419
+ }, e => reject(common__namespace.fail(e)));
420
+ }, e => reject(common__namespace.fail(e)));
421
+ }, e => reject(common__namespace.fail(e)));
422
+ });
423
+ }
424
+ function templatizeDatasources(itemTemplate, authentication, portalUrl) {
425
+ return new Promise((resolve, reject) => {
426
+ const dataSources = common__namespace.getProp(itemTemplate, "data.dataSource.dataSources");
427
+ if (dataSources && Object.keys(dataSources).length > 0) {
428
+ const pendingRequests = new Array();
429
+ Object.keys(dataSources).forEach(k => {
430
+ const ds = dataSources[k];
431
+ common__namespace.setProp(ds, "portalUrl", common__namespace.placeholder(common__namespace.SERVER_NAME));
432
+ const itemId = common__namespace.getProp(ds, "itemId");
433
+ if (common__namespace.getProp(ds, "url")) {
434
+ if (itemId) {
435
+ const layerId = ds.url.substr(ds.url.lastIndexOf("/") + 1);
436
+ ds.itemId = common__namespace.templatizeTerm(itemId, itemId, ".layer" + layerId + ".itemId");
437
+ }
438
+ const urlResults = findUrls(ds.url, portalUrl, [], [], authentication);
439
+ pendingRequests.push(new Promise((resolveReq, rejectReq) => {
440
+ handleServiceRequests(urlResults.serviceRequests, urlResults.requestUrls, urlResults.testString).then(response => {
441
+ ds.url = response;
442
+ resolveReq();
443
+ }, e => rejectReq(common__namespace.fail(e)));
444
+ }));
445
+ }
446
+ else {
447
+ if (itemId) {
448
+ ds.itemId = common__namespace.templatizeTerm(itemId, itemId, ".itemId");
449
+ }
450
+ }
451
+ });
452
+ Promise.all(pendingRequests).then(() => resolve(itemTemplate), e => reject(common__namespace.fail(e)));
453
+ }
454
+ else {
455
+ resolve(itemTemplate);
456
+ }
457
+ });
458
+ }
459
+ function templatizeWidgets(itemTemplate, authentication, portalUrl, widgetPath, isOnScreen = false) {
460
+ return new Promise((resolve, reject) => {
461
+ // update widgets
462
+ const widgets = common__namespace.getProp(itemTemplate, widgetPath) || [];
463
+ let serviceRequests = [];
464
+ let requestUrls = [];
465
+ widgets.forEach(widget => {
466
+ /* istanbul ignore else */
467
+ if (!isOnScreen && common__namespace.getProp(widget, "icon")) {
468
+ setValues(widget, ["icon"], common__namespace.placeholder(common__namespace.SERVER_NAME));
469
+ }
470
+ const config = widget.config;
471
+ if (config) {
472
+ const sConfig = JSON.stringify(config);
473
+ const urlResults = findUrls(sConfig, portalUrl, requestUrls, serviceRequests, authentication);
474
+ widget.config = JSON.parse(urlResults.testString);
475
+ serviceRequests = urlResults.serviceRequests;
476
+ requestUrls = urlResults.requestUrls;
477
+ }
478
+ });
479
+ if (serviceRequests.length > 0) {
480
+ const sWidgets = JSON.stringify(widgets);
481
+ handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(response => {
482
+ common__namespace.setProp(itemTemplate, widgetPath, JSON.parse(response));
483
+ resolve(itemTemplate);
484
+ }, e => reject(common__namespace.fail(e)));
485
+ }
486
+ else {
487
+ resolve(itemTemplate);
488
+ }
489
+ });
490
+ }
491
+ function templatizeValues(itemTemplate, authentication, portalUrl, widgetPath) {
492
+ return new Promise((resolve, reject) => {
493
+ // update properties of values collection for web app templates
494
+ let values = common__namespace.getProp(itemTemplate, widgetPath);
495
+ let serviceRequests = [];
496
+ let requestUrls = [];
497
+ if (values) {
498
+ if (common__namespace.getProp(values, "icon")) {
499
+ setValues(values, ["icon"], common__namespace.placeholder(common__namespace.SERVER_NAME));
500
+ }
501
+ const sConfig = JSON.stringify(values);
502
+ const urlResults = findUrls(sConfig, portalUrl, requestUrls, serviceRequests, authentication);
503
+ values = JSON.parse(urlResults.testString);
504
+ serviceRequests = urlResults.serviceRequests;
505
+ requestUrls = urlResults.requestUrls;
506
+ }
507
+ if (serviceRequests.length > 0) {
508
+ const sWidgets = JSON.stringify(values);
509
+ handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(response => {
510
+ common__namespace.setProp(itemTemplate, widgetPath, JSON.parse(response));
511
+ resolve(itemTemplate);
512
+ }, e => reject(common__namespace.fail(e)));
513
+ }
514
+ else {
515
+ resolve(itemTemplate);
516
+ }
517
+ });
518
+ }
519
+ function handleServiceRequests(serviceRequests, requestUrls, objString) {
520
+ return new Promise((resolve, reject) => {
521
+ if (serviceRequests && serviceRequests.length > 0) {
522
+ let i = 0;
523
+ Promise.all(serviceRequests).then(serviceResponses => {
524
+ serviceResponses.forEach(serviceResponse => {
525
+ if (common__namespace.getProp(serviceResponse, "serviceItemId")) {
526
+ const serviceTemplate = "{{" +
527
+ serviceResponse.serviceItemId +
528
+ (serviceResponse.hasOwnProperty("id")
529
+ ? ".layer" + serviceResponse.id
530
+ : "") +
531
+ ".url}}";
532
+ objString = replaceUrl(objString, requestUrls[i], serviceTemplate, true);
533
+ }
534
+ i++;
535
+ });
536
+ resolve(objString);
537
+ }, e => reject(common__namespace.fail(e)));
538
+ }
539
+ else {
540
+ resolve(objString);
541
+ }
542
+ });
543
+ }
544
+ function findUrls(testString, portalUrl, requestUrls, serviceRequests, authentication) {
545
+ const options = {
546
+ f: "json",
547
+ authentication: authentication
548
+ };
549
+ // test for URLs
550
+ const results = testString.match(/(\bhttps?:\/\/[-A-Z0-9/._]*)/gim);
551
+ if (results && results.length) {
552
+ results.forEach((url) => {
553
+ if (url.indexOf("NAServer") > -1) {
554
+ testString = replaceUrl(testString, url, common__namespace.placeholder(common__namespace.NA_SERVER_NAME));
555
+ }
556
+ else if (url.indexOf("GeocodeServer") > -1) {
557
+ testString = replaceUrl(testString, url, common__namespace.placeholder(common__namespace.GEOCODE_SERVER_NAME));
558
+ }
559
+ else if (portalUrl && url.indexOf(portalUrl) > -1) {
560
+ testString = replaceUrl(testString, portalUrl, common__namespace.placeholder(common__namespace.SERVER_NAME));
561
+ }
562
+ else if (url.indexOf("FeatureServer") > -1) {
563
+ if (requestUrls.indexOf(url) === -1) {
564
+ requestUrls.push(url);
565
+ serviceRequests.push(common__namespace.rest_request(url, options));
566
+ }
567
+ }
568
+ });
569
+ }
570
+ return {
571
+ testString,
572
+ requestUrls,
573
+ serviceRequests
574
+ };
575
+ }
576
+ /**
577
+ * Replace url with templatized url value
578
+ *
579
+ * @param obj can be a single url string or a stringified JSON object
580
+ * @param url the current url we are testing for
581
+ * @param newUrl the templatized url
582
+ * @param validateFullUrl should only replace url when we have a full match.
583
+ * This property is only relevant when the obj is a stringified JSON object.
584
+ *
585
+ * @returns the obj with any instances of the url replaced
586
+ */
587
+ function replaceUrl(obj, url, newUrl, validateFullUrl = false) {
588
+ const enforceFullUrl = validateFullUrl && obj.indexOf('"') > -1;
589
+ const re = new RegExp(enforceFullUrl ? '"' + url + '"' : url, "gmi");
590
+ return obj.replace(re, enforceFullUrl ? '"' + newUrl + '"' : newUrl);
591
+ }
592
+ function setValues(itemTemplate, paths, base) {
593
+ paths.forEach(path => {
594
+ const url = common__namespace.getProp(itemTemplate, path);
595
+ if (url) {
596
+ const subString = url.substring(url.indexOf("/", url.indexOf("//") + 2));
597
+ common__namespace.setProp(itemTemplate, path, subString !== url ? base + subString : base);
598
+ }
599
+ });
600
+ }
601
+ function fineTuneCreatedItem$2(originalTemplate, newlyCreatedItem, templateDictionary, destinationAuthentication) {
602
+ return new Promise(resolve => {
603
+ // If this is a Web AppBuilder application, we will create a Code Attachment for downloading
604
+ if (common__namespace.hasAnyKeyword(originalTemplate, [
605
+ "WAB2D",
606
+ "WAB3D",
607
+ "Web AppBuilder"
608
+ ])) {
609
+ // Update item so properties like appItemId can now be set now that we know the new apps ID
610
+ const updateOptions = {
611
+ id: newlyCreatedItem.itemId,
612
+ url: newlyCreatedItem.item.url,
613
+ data: newlyCreatedItem.data
614
+ };
615
+ const updateDef = common__namespace.updateItem(updateOptions, destinationAuthentication);
616
+ const itemInfo = {
617
+ tags: originalTemplate.item.tags,
618
+ title: originalTemplate.item.title,
619
+ type: "Code Attachment",
620
+ typeKeywords: ["Code", "Javascript", "Web Mapping Application"],
621
+ relationshipType: "WMA2Code",
622
+ originItemId: newlyCreatedItem.itemId,
623
+ url: common__namespace.checkUrlPathTermination(common__namespace.replaceInTemplate(common__namespace.placeholder(common__namespace.SERVER_NAME), templateDictionary)) +
624
+ "sharing/rest/content/items/" +
625
+ newlyCreatedItem.itemId +
626
+ "/package"
627
+ };
628
+ const createItemWithDataDef = common__namespace.createItemWithData(itemInfo, {}, destinationAuthentication, templateDictionary.folderId);
629
+ Promise.all([updateDef, createItemWithDataDef]).then(() => resolve(null), () => resolve(null));
630
+ }
631
+ else {
632
+ // Otherwise, nothing extra needed
633
+ resolve(null);
634
+ }
635
+ });
636
+ }
637
+ // ------------------------------------------------------------------------------------------------------------------ //
638
+ /**
639
+ * Gets the ids of the dependencies of an AGOL webapp item.
640
+ *
641
+ * @param fullItem A webapp item whose dependencies are sought
642
+ * @return A promise that will resolve with list of dependent ids
643
+ * @protected
644
+ */
645
+ function _extractDependencies$2(model) {
646
+ let processor = _getGenericWebAppDependencies;
647
+ /*
648
+ if (common.hasTypeKeyword(model, "Story Map")) {
649
+ processor = getStoryMapDependencies;
650
+ }
651
+ */
652
+ if (common__namespace.hasAnyKeyword(model, ["WAB2D", "WAB3D", "Web AppBuilder"])) {
653
+ processor = _getWABDependencies;
654
+ }
655
+ return processor(model);
656
+ }
657
+ /**
658
+ * Generic Web App Dependencies
659
+ */
660
+ function _getGenericWebAppDependencies(model) {
661
+ const props = ["data.values.webmap", "data.values.group"];
662
+ return common__namespace.getProps(model, props);
663
+ }
664
+ function _getWABDependencies(model) {
665
+ const deps = [];
666
+ const v = common__namespace.getProp(model, "data.map.itemId");
667
+ if (v) {
668
+ deps.push(v);
669
+ }
670
+ const dataSources = common__namespace.getProp(model, "data.dataSource.dataSources");
671
+ if (dataSources) {
672
+ Object.keys(dataSources).forEach(k => {
673
+ const ds = dataSources[k];
674
+ if (ds.itemId) {
675
+ deps.push(ds.itemId);
676
+ }
677
+ });
678
+ }
679
+ return deps;
680
+ }
681
+ /**
682
+ * Templatizes id properties for the paths provided
683
+ *
684
+ * @param itemTemplate The solution item template
685
+ * @param paths A list of property paths that contain ids
686
+ * @protected
687
+ */
688
+ function _templatizeIdPaths(itemTemplate, paths) {
689
+ paths.forEach(path => {
690
+ const id = common__namespace.getProp(itemTemplate, path);
691
+ _templatizeIdPath(itemTemplate, path, id);
692
+ });
693
+ }
694
+ /**
695
+ * Templatizes id property for the path provided
696
+ *
697
+ * @param itemTemplate The solution item template
698
+ * @param path A path to an id property
699
+ * @param id The base id to use when templatizing
700
+ * @protected
701
+ */
702
+ function _templatizeIdPath(itemTemplate, path, id) {
703
+ common__namespace.setProp(itemTemplate, path, common__namespace.templatizeTerm(id, id, ".itemId"));
704
+ }
705
+ /**
706
+ * Templatize field references for datasources and widgets.
707
+ *
708
+ * @param solutionTemplate The solution item template
709
+ * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
710
+ * @returns The solutionTemplate with templatized field references
711
+ */
712
+ function postProcessFieldReferences$2(solutionTemplate, datasourceInfos) {
713
+ // handle datasources common for WAB apps
714
+ const dataSources = common__namespace.getProp(solutionTemplate, "data.dataSource.dataSources");
715
+ if (dataSources && Object.keys(dataSources).length > 0) {
716
+ Object.keys(dataSources).forEach(k => {
717
+ const ds = dataSources[k];
718
+ dataSources[k] = _templatizeObject(ds, datasourceInfos);
719
+ });
720
+ common__namespace.setProp(solutionTemplate, "data.dataSource.dataSources", dataSources);
721
+ }
722
+ // handle widgets common for WAB apps
723
+ const paths = [
724
+ "data.widgetPool.widgets",
725
+ "data.widgetOnScreen.widgets"
726
+ ];
727
+ paths.forEach(path => {
728
+ const widgets = common__namespace.getProp(solutionTemplate, path);
729
+ if (widgets) {
730
+ common__namespace.setProp(solutionTemplate, path, _templatizeObjectArray(widgets, datasourceInfos));
731
+ }
732
+ });
733
+ // handle values common for web app templates
734
+ const values = common__namespace.getProp(solutionTemplate, "data.values");
735
+ if (values) {
736
+ common__namespace.setProp(solutionTemplate, "data.values", _templatizeObject(values, datasourceInfos));
737
+ }
738
+ return solutionTemplate;
739
+ }
740
+ /**
741
+ * Templatize field references for given dataSource from the web application.
742
+ *
743
+ * @param obj The dataSource or widget object from the web application.
744
+ * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
745
+ * @returns The dataSource with templatized field references
746
+ */
747
+ function _templatizeObject(obj, datasourceInfos, templatizeKeys = false) {
748
+ obj = _prioritizedTests(obj, datasourceInfos, templatizeKeys);
749
+ const replaceOrder = _getReplaceOrder(obj, datasourceInfos);
750
+ replaceOrder.forEach(ds => {
751
+ obj = common__namespace.templatizeFieldReferences(obj, ds.fields, ds.basePath, templatizeKeys);
752
+ });
753
+ return obj;
754
+ }
755
+ /**
756
+ * Templatize field references from an array of various objects from the web application.
757
+ *
758
+ * @param objects A list of widgets or objects from the web application that may contain field references.
759
+ * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
760
+ * @returns The widgets with templatized field references
761
+ */
762
+ function _templatizeObjectArray(objects, datasourceInfos) {
763
+ const updateKeyObjects = ["SmartEditor", "Screening"];
764
+ return objects.map(obj => {
765
+ // only templatize the config and lower
766
+ if (obj.config) {
767
+ const templatizeKeys = updateKeyObjects.indexOf(obj.name) > -1;
768
+ obj.config = _templatizeObject(obj.config, datasourceInfos, templatizeKeys);
769
+ }
770
+ return obj;
771
+ });
772
+ }
773
+ /**
774
+ * Gets an order for testing wit the various datasource info objects against the widget or dataSource.
775
+ * A widget or dataSource that contain a layers url or webmap layer id are more likely
776
+ * to have field references from that layer.
777
+ *
778
+ * @param obj The dataSource or widget object from the web application.
779
+ * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
780
+ * @returns A list of datasourceInfo objects sorted based on the presence of a layers url or id
781
+ */
782
+ function _getReplaceOrder(obj, datasourceInfos) {
783
+ const objString = JSON.stringify(obj);
784
+ // If we don't find any layer url, web map layer id, service url, agol itemId then remove the datasource.
785
+ const _datasourceInfos = datasourceInfos.filter(ds => _getSortOrder(ds, objString) < 4);
786
+ return _datasourceInfos.sort((a, b) => {
787
+ return _getSortOrder(a, objString) - _getSortOrder(b, objString);
788
+ });
789
+ }
790
+ /**
791
+ * Determine an order for checking field names against a dataSource or widget.
792
+ * Sort order preference is set in this order: layer url, web map layer id, service url, agol itemId
793
+ *
794
+ * @param datasourceInfo The datasource object with key properties about the service.
795
+ * @param testString A stringified version of a widget or dataSource
796
+ * @returns The prioritized order for testing
797
+ */
798
+ function _getSortOrder(datasourceInfo, testString) {
799
+ const url = datasourceInfo.url;
800
+ const itemId = datasourceInfo.itemId;
801
+ const layerId = datasourceInfo.layerId;
802
+ // if we have the url and the layerID and its found prioritize it first
803
+ // else if we find the maps layer id prioritze it first
804
+ let layerUrlTest;
805
+ if (url && !isNaN(layerId)) {
806
+ layerUrlTest = new RegExp(url.replace(/[.]/, ".layer" + layerId + "."), "gm");
807
+ }
808
+ if (layerUrlTest && layerUrlTest.test(testString)) {
809
+ return 1;
810
+ }
811
+ else if (datasourceInfo.ids.length > 0) {
812
+ if (datasourceInfo.ids.some(id => {
813
+ const layerMapIdTest = new RegExp(id, "gm");
814
+ return layerMapIdTest.test(testString);
815
+ })) {
816
+ return 1;
817
+ }
818
+ }
819
+ // if neither full layer url or map layer id are found...check to see if we can
820
+ // find the base service url
821
+ if (url) {
822
+ const serviceUrlTest = new RegExp(url, "gm");
823
+ if (serviceUrlTest.test(testString)) {
824
+ return 2;
825
+ }
826
+ }
827
+ // if none of the above see if we can find an AGOL item id reference
828
+ if (itemId) {
829
+ const itemIdTest = new RegExp(itemId, "gm");
830
+ if (itemIdTest.test(testString)) {
831
+ return 3;
832
+ }
833
+ }
834
+ return 4;
835
+ }
836
+ /**
837
+ * These tests will run prior to the tests associated with the higher level tests based on sort order.
838
+ * The tests work more like cloning an object where we go through and review each individual property.
839
+ * If we find a url or webmap layer id we will templatize the parent object that contains this property.
840
+ * Many widgets will store one of these two properties in an object that will also contain various field references.
841
+ *
842
+ * @param obj The dataSource or widget object from the application
843
+ * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
844
+ * @returns An updated instance of the dataSource or widget with as many field references templatized as possible.
845
+ */
846
+ function _prioritizedTests(obj, datasourceInfos, templatizeKeys) {
847
+ const objString = JSON.stringify(obj);
848
+ const hasDatasources = datasourceInfos.filter(ds => {
849
+ let urlTest;
850
+ if (ds.url && !isNaN(ds.layerId)) {
851
+ urlTest = new RegExp(ds.url.replace(/[.]/, ".layer" + ds.layerId + "."), "gm");
852
+ }
853
+ let hasMapLayerId = false;
854
+ if (ds.ids.length > 0) {
855
+ hasMapLayerId = ds.ids.some(id => {
856
+ const idTest = new RegExp(id, "gm");
857
+ return idTest.test(objString);
858
+ });
859
+ }
860
+ if (hasMapLayerId || (urlTest && urlTest.test(objString))) {
861
+ return ds;
862
+ }
863
+ });
864
+ if (hasDatasources.length > 0) {
865
+ hasDatasources.forEach(ds => {
866
+ // specific url reference is the most common
867
+ obj = _templatizeParentByURL(obj, ds, templatizeKeys);
868
+ if (ds.ids.length > 0) {
869
+ // the second most common is to use the layerId from the webmap
870
+ ds.ids.forEach(id => {
871
+ obj = _templatizeParentByWebMapLayerId(obj, ds, id, templatizeKeys);
872
+ });
873
+ }
874
+ });
875
+ }
876
+ return obj;
877
+ }
878
+ /**
879
+ * This is very close to common.cloneObject but will test if an object
880
+ * has one of the datasource urls as a property. If it finds one it will
881
+ * templatize it's parent based on the fields from that datasource
882
+ *
883
+ * @param obj The dataSource or widget object from the application
884
+ * @param ds A datasourceInfo object to use for testing against the current dataSource or widget
885
+ * @returns The updated instance of the object with as many field references templatized as possible
886
+ */
887
+ function _templatizeParentByURL(obj, ds, templatizeKeys) {
888
+ let clone = {};
889
+ const url = ds.url;
890
+ const layerId = ds.layerId;
891
+ let urlTest;
892
+ if (url && !isNaN(layerId)) {
893
+ urlTest = new RegExp(url.replace(/[.]/, ".layer" + layerId + "."), "gm");
894
+ }
895
+ if (Array.isArray(obj)) {
896
+ clone = obj.map(c => {
897
+ return _templatizeParentByURL(c, ds, templatizeKeys);
898
+ });
899
+ }
900
+ else if (typeof obj === "object") {
901
+ for (const i in obj) {
902
+ if (obj[i] != null && typeof obj[i] === "object") {
903
+ clone[i] = _templatizeParentByURL(obj[i], ds, templatizeKeys);
904
+ }
905
+ else {
906
+ if (urlTest && urlTest.test(obj[i])) {
907
+ obj = common__namespace.templatizeFieldReferences(obj, ds.fields, ds.basePath, templatizeKeys);
908
+ }
909
+ clone[i] = obj[i];
910
+ }
911
+ }
912
+ }
913
+ else {
914
+ clone = obj;
915
+ }
916
+ return clone;
917
+ }
918
+ /**
919
+ * This is very close to common.cloneObject but will test if an object
920
+ * has one of the datasource webmap layer ids as a property. If it finds one it will
921
+ * templatize it's parent based on the fields from that datasource.
922
+ *
923
+ * @param obj The dataSource or widget object from the application
924
+ * @param ds A datasourceInfo object to use for testing against the current dataSource or widget
925
+ * @param id A webmap layer id to test with.
926
+ * @returns The updated instance of the object with as many field references templatized as possible
927
+ */
928
+ function _templatizeParentByWebMapLayerId(obj, ds, id, templatizeKeys) {
929
+ let clone = {};
930
+ const idTest = new RegExp(id, "gm");
931
+ if (Array.isArray(obj)) {
932
+ clone = obj.map(c => {
933
+ return _templatizeParentByWebMapLayerId(c, ds, id, templatizeKeys);
934
+ });
935
+ }
936
+ else if (typeof obj === "object") {
937
+ for (const i in obj) {
938
+ if (obj[i] !== null) {
939
+ // In some web application templates they store a stringified version of an object that can
940
+ // contain multiple layer references at a very high level on the main values collection.
941
+ // This was causing many other more typical layer references to be set incorrectly as the first
942
+ // layerId found in this high level string would be used against the main object.
943
+ let parsedProp;
944
+ try {
945
+ parsedProp = JSON.parse(obj[i]);
946
+ }
947
+ catch (error) {
948
+ parsedProp = undefined;
949
+ }
950
+ if (parsedProp && typeof parsedProp === "object") {
951
+ clone[i] = JSON.stringify(_templatizeParentByWebMapLayerId(parsedProp, ds, id, templatizeKeys));
952
+ }
953
+ else if (typeof obj[i] === "object") {
954
+ // some widgets store the layerId as a key to a collection of details that contain field references
955
+ if (idTest.test(i) && templatizeKeys) {
956
+ obj[i] = common__namespace.templatizeFieldReferences(obj[i], ds.fields, ds.basePath, templatizeKeys);
957
+ }
958
+ clone[i] = _templatizeParentByWebMapLayerId(obj[i], ds, id, templatizeKeys);
959
+ }
960
+ else {
961
+ if (idTest.test(obj[i])) {
962
+ obj = common__namespace.templatizeFieldReferences(obj, ds.fields, ds.basePath, templatizeKeys);
963
+ }
964
+ clone[i] = obj[i];
965
+ }
966
+ }
967
+ else {
968
+ clone[i] = obj[i];
969
+ }
970
+ }
971
+ }
972
+ else {
973
+ clone = obj;
974
+ }
975
+ return clone;
976
+ }
1028
977
 
1029
- /** @license
1030
- * Copyright 2020 Esri
1031
- *
1032
- * Licensed under the Apache License, Version 2.0 (the "License");
1033
- * you may not use this file except in compliance with the License.
1034
- * You may obtain a copy of the License at
1035
- *
1036
- * http://www.apache.org/licenses/LICENSE-2.0
1037
- *
1038
- * Unless required by applicable law or agreed to in writing, software
1039
- * distributed under the License is distributed on an "AS IS" BASIS,
1040
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1041
- * See the License for the specific language governing permissions and
1042
- * limitations under the License.
1043
- */
1044
- function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
1045
- return new Promise(function (resolve) {
1046
- // Interrupt process if progress callback returns `false`
1047
- if (!itemProgressCallback(template.itemId, common.EItemProgressStatus.Started, 0)) {
1048
- itemProgressCallback(template.itemId, common.EItemProgressStatus.Ignored, 0);
1049
- resolve(common.generateEmptyCreationResponse(template.type));
1050
- }
1051
- else {
1052
- // Replace the templatized symbols in a copy of the template
1053
- var newItemTemplate_1 = common.cloneObject(template);
1054
- newItemTemplate_1 = common.replaceInTemplate(newItemTemplate_1, templateDictionary);
1055
- // Create the item, then update its URL with its new id
1056
- // some fieldnames are used as keys for objects
1057
- // when we templatize field references for web applications we first stringify the components of the
1058
- // web application that could contain field references and then serach for them with a regular expression.
1059
- // We also need to stringify the web application when de-templatizing so it will find all of these occurrences as well.
1060
- if (template.type === "Web Mapping Application" && template.data) {
1061
- newItemTemplate_1 = JSON.parse(common.replaceInTemplate(JSON.stringify(newItemTemplate_1), templateDictionary));
1062
- }
1063
- if (template.item.thumbnail) {
1064
- newItemTemplate_1.item.thumbnail = template.item.thumbnail; // make sure that our File is still there
1065
- }
1066
- common.createItemWithData(newItemTemplate_1.item, newItemTemplate_1.data, destinationAuthentication, templateDictionary.folderId)
1067
- .then(function (createResponse) {
1068
- // Interrupt process if progress callback returns `false`
1069
- if (!itemProgressCallback(template.itemId, common.EItemProgressStatus.Created, template.estimatedDeploymentCostFactor / 2, createResponse.id)) {
1070
- itemProgressCallback(template.itemId, common.EItemProgressStatus.Cancelled, 0);
1071
- common.removeItem(createResponse.id, destinationAuthentication)
1072
- .then(function () {
1073
- return resolve(common.generateEmptyCreationResponse(template.type));
1074
- }, function () {
1075
- return resolve(common.generateEmptyCreationResponse(template.type));
1076
- });
1077
- }
1078
- else {
1079
- // Add the new item to the settings
1080
- templateDictionary[template.itemId] = {
1081
- itemId: createResponse.id
1082
- };
1083
- newItemTemplate_1.itemId = createResponse.id;
1084
- // Set the appItemId manually to get around cases where the path was incorrectly set
1085
- // in legacy deployments
1086
- if (newItemTemplate_1.type === "Web Mapping Application" &&
1087
- template.data) {
1088
- common.setProp(newItemTemplate_1, "data.appItemId", createResponse.id);
1089
- }
1090
- var postProcess_1 = common.hasUnresolvedVariables(newItemTemplate_1.data);
1091
- // Update the template again now that we have the new item id
1092
- var originalURL = newItemTemplate_1.item.url;
1093
- newItemTemplate_1 = common.replaceInTemplate(newItemTemplate_1, templateDictionary);
1094
- // Update relationships
1095
- var relationshipsDef = Promise.resolve([]);
1096
- if (newItemTemplate_1.relatedItems) {
1097
- // Templatize references in relationships obj
1098
- var updatedRelatedItems = common.replaceInTemplate(common.templatizeIds(newItemTemplate_1.relatedItems), templateDictionary);
1099
- // Add the relationships
1100
- relationshipsDef = common.addForwardItemRelationships(newItemTemplate_1.itemId, updatedRelatedItems, destinationAuthentication);
1101
- }
1102
- // Check for extra processing for web mapping application et al.
1103
- var customProcDef = void 0;
1104
- if (template.type === "Web Mapping Application" &&
1105
- template.data &&
1106
- common.hasAnyKeyword(template, [
1107
- "WAB2D",
1108
- "WAB3D",
1109
- "Web AppBuilder"
1110
- ])) {
1111
- // If this is a Web AppBuilder application, we will create a Code Attachment for downloading
1112
- customProcDef = fineTuneCreatedItem(template, newItemTemplate_1, templateDictionary, destinationAuthentication);
1113
- }
1114
- else if (template.type === "Workforce Project") {
1115
- customProcDef = fineTuneCreatedItem$1(newItemTemplate_1, destinationAuthentication, templateDictionary);
1116
- }
1117
- else if (template.type === "Notebook") {
1118
- customProcDef = fineTuneCreatedItem$2(template, newItemTemplate_1, templateDictionary, destinationAuthentication);
1119
- }
1120
- else if (originalURL !== newItemTemplate_1.item.url) {
1121
- // For web mapping applications that are not Web AppBuilder apps
1122
- customProcDef = new Promise(function (resolve2, reject2) {
1123
- common.updateItemURL(createResponse.id, newItemTemplate_1.item.url, destinationAuthentication)
1124
- .then(function () { return resolve2(); }, reject2);
1125
- });
1126
- }
1127
- else {
1128
- customProcDef = Promise.resolve(null);
1129
- }
1130
- Promise.all([relationshipsDef, customProcDef]).then(function () {
1131
- // Interrupt process if progress callback returns `false`
1132
- if (!itemProgressCallback(template.itemId, common.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor / 2, createResponse.id)) {
1133
- itemProgressCallback(template.itemId, common.EItemProgressStatus.Cancelled, 0);
1134
- common.removeItem(createResponse.id, destinationAuthentication)
1135
- .then(function () {
1136
- return resolve(common.generateEmptyCreationResponse(template.type));
1137
- }, function () {
1138
- return resolve(common.generateEmptyCreationResponse(template.type));
1139
- });
1140
- }
1141
- else {
1142
- resolve({
1143
- item: newItemTemplate_1,
1144
- id: createResponse.id,
1145
- type: newItemTemplate_1.type,
1146
- postProcess: postProcess_1
1147
- });
1148
- }
1149
- }, function () {
1150
- itemProgressCallback(template.itemId, common.EItemProgressStatus.Failed, 0);
1151
- resolve(common.generateEmptyCreationResponse(template.type)); // fails to deploy all resources to the item
1152
- });
1153
- }
1154
- }, function () {
1155
- itemProgressCallback(template.itemId, common.EItemProgressStatus.Failed, 0);
1156
- resolve(common.generateEmptyCreationResponse(template.type)); // fails to create item
1157
- });
1158
- }
1159
- });
1160
- }
978
+ /** @license
979
+ * Copyright 2018 Esri
980
+ *
981
+ * Licensed under the Apache License, Version 2.0 (the "License");
982
+ * you may not use this file except in compliance with the License.
983
+ * You may obtain a copy of the License at
984
+ *
985
+ * http://www.apache.org/licenses/LICENSE-2.0
986
+ *
987
+ * Unless required by applicable law or agreed to in writing, software
988
+ * distributed under the License is distributed on an "AS IS" BASIS,
989
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
990
+ * See the License for the specific language governing permissions and
991
+ * limitations under the License.
992
+ */
993
+ /**
994
+ * Converts an workforce item to a template.
995
+ *
996
+ * @param itemTemplate template for the workforce project item
997
+ * @param destAuthentication Credentials for requests to the destination organization
998
+ * @param srcAuthentication Credentials for requests to source items
999
+ * @return templatized itemTemplate
1000
+ */
1001
+ function convertItemToTemplate$6(itemTemplate, destAuthentication, srcAuthentication) {
1002
+ return common__namespace.convertWorkforceItemToTemplate(itemTemplate, srcAuthentication);
1003
+ }
1004
+ /**
1005
+ * Gets the current user and updates the dispatchers service
1006
+ *
1007
+ * @param newlyCreatedItem Item to be created; n.b.: this item is modified
1008
+ * @param destinationAuthentication The session used to create the new item(s)
1009
+ * @return A promise that will resolve with { "success" === true || false }
1010
+ */
1011
+ function fineTuneCreatedItem$1(newlyCreatedItem, destinationAuthentication, templateDictionary) {
1012
+ return common__namespace.fineTuneCreatedWorkforceItem(newlyCreatedItem, destinationAuthentication, "", templateDictionary);
1013
+ }
1161
1014
 
1162
- /** @license
1163
- * Copyright 2020 Esri
1164
- *
1165
- * Licensed under the Apache License, Version 2.0 (the "License");
1166
- * you may not use this file except in compliance with the License.
1167
- * You may obtain a copy of the License at
1168
- *
1169
- * http://www.apache.org/licenses/LICENSE-2.0
1170
- *
1171
- * Unless required by applicable law or agreed to in writing, software
1172
- * distributed under the License is distributed on an "AS IS" BASIS,
1173
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1174
- * See the License for the specific language governing permissions and
1175
- * limitations under the License.
1176
- */
1177
- function updateNotebookData(itemId, data, authentication) {
1178
- var updateOptions = {
1179
- id: itemId,
1180
- data: common.jsonToBlob(data)
1181
- };
1182
- return common.updateItem(updateOptions, authentication);
1183
- }
1015
+ /** @license
1016
+ * Copyright 2020 Esri
1017
+ *
1018
+ * Licensed under the Apache License, Version 2.0 (the "License");
1019
+ * you may not use this file except in compliance with the License.
1020
+ * You may obtain a copy of the License at
1021
+ *
1022
+ * http://www.apache.org/licenses/LICENSE-2.0
1023
+ *
1024
+ * Unless required by applicable law or agreed to in writing, software
1025
+ * distributed under the License is distributed on an "AS IS" BASIS,
1026
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1027
+ * See the License for the specific language governing permissions and
1028
+ * limitations under the License.
1029
+ */
1030
+ function createItemFromTemplate$3(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
1031
+ return new Promise(resolve => {
1032
+ // Interrupt process if progress callback returns `false`
1033
+ if (!itemProgressCallback(template.itemId, common__namespace.EItemProgressStatus.Started, 0)) {
1034
+ itemProgressCallback(template.itemId, common__namespace.EItemProgressStatus.Ignored, 0);
1035
+ resolve(common__namespace.generateEmptyCreationResponse(template.type));
1036
+ }
1037
+ else {
1038
+ // Replace the templatized symbols in a copy of the template
1039
+ let newItemTemplate = common__namespace.cloneObject(template);
1040
+ newItemTemplate = common__namespace.replaceInTemplate(newItemTemplate, templateDictionary);
1041
+ // Create the item, then update its URL with its new id
1042
+ // some fieldnames are used as keys for objects
1043
+ // when we templatize field references for web applications we first stringify the components of the
1044
+ // web application that could contain field references and then serach for them with a regular expression.
1045
+ // We also need to stringify the web application when de-templatizing so it will find all of these occurrences as well.
1046
+ if (template.type === "Web Mapping Application" && template.data) {
1047
+ newItemTemplate = JSON.parse(common__namespace.replaceInTemplate(JSON.stringify(newItemTemplate), templateDictionary));
1048
+ }
1049
+ if (template.item.thumbnail) {
1050
+ newItemTemplate.item.thumbnail = template.item.thumbnail; // make sure that our File is still there
1051
+ }
1052
+ common__namespace
1053
+ .createItemWithData(newItemTemplate.item, newItemTemplate.data, destinationAuthentication, templateDictionary.folderId)
1054
+ .then(createResponse => {
1055
+ // Interrupt process if progress callback returns `false`
1056
+ if (!itemProgressCallback(template.itemId, common__namespace.EItemProgressStatus.Created, template.estimatedDeploymentCostFactor / 2, createResponse.id)) {
1057
+ itemProgressCallback(template.itemId, common__namespace.EItemProgressStatus.Cancelled, 0);
1058
+ common__namespace
1059
+ .removeItem(createResponse.id, destinationAuthentication)
1060
+ .then(() => resolve(common__namespace.generateEmptyCreationResponse(template.type)), () => resolve(common__namespace.generateEmptyCreationResponse(template.type)));
1061
+ }
1062
+ else {
1063
+ // Add the new item to the settings
1064
+ templateDictionary[template.itemId] = {
1065
+ itemId: createResponse.id
1066
+ };
1067
+ newItemTemplate.itemId = createResponse.id;
1068
+ // Set the appItemId manually to get around cases where the path was incorrectly set
1069
+ // in legacy deployments
1070
+ if (newItemTemplate.type === "Web Mapping Application" &&
1071
+ template.data) {
1072
+ common__namespace.setProp(newItemTemplate, "data.appItemId", createResponse.id);
1073
+ }
1074
+ const postProcess = common__namespace.hasUnresolvedVariables(newItemTemplate.data);
1075
+ // Update the template again now that we have the new item id
1076
+ const originalURL = newItemTemplate.item.url;
1077
+ newItemTemplate = common__namespace.replaceInTemplate(newItemTemplate, templateDictionary);
1078
+ // Update relationships
1079
+ let relationshipsDef = Promise.resolve([]);
1080
+ if (newItemTemplate.relatedItems) {
1081
+ // Templatize references in relationships obj
1082
+ const updatedRelatedItems = common__namespace.replaceInTemplate(common__namespace.templatizeIds(newItemTemplate.relatedItems), templateDictionary);
1083
+ // Add the relationships
1084
+ relationshipsDef = common__namespace.addForwardItemRelationships(newItemTemplate.itemId, updatedRelatedItems, destinationAuthentication);
1085
+ }
1086
+ // Check for extra processing for web mapping application et al.
1087
+ let customProcDef;
1088
+ if (template.type === "Web Mapping Application" &&
1089
+ template.data &&
1090
+ common__namespace.hasAnyKeyword(template, [
1091
+ "WAB2D",
1092
+ "WAB3D",
1093
+ "Web AppBuilder"
1094
+ ])) {
1095
+ // If this is a Web AppBuilder application, we will create a Code Attachment for downloading
1096
+ customProcDef = fineTuneCreatedItem$2(template, newItemTemplate, templateDictionary, destinationAuthentication);
1097
+ }
1098
+ else if (template.type === "Workforce Project") {
1099
+ customProcDef = fineTuneCreatedItem$1(newItemTemplate, destinationAuthentication, templateDictionary);
1100
+ }
1101
+ else if (template.type === "Notebook") {
1102
+ customProcDef = fineTuneCreatedItem(template, newItemTemplate, templateDictionary, destinationAuthentication);
1103
+ }
1104
+ else if (originalURL !== newItemTemplate.item.url) {
1105
+ // For web mapping applications that are not Web AppBuilder apps
1106
+ customProcDef = new Promise((resolve2, reject2) => {
1107
+ common__namespace
1108
+ .updateItemURL(createResponse.id, newItemTemplate.item.url, destinationAuthentication)
1109
+ .then(() => resolve2(), reject2);
1110
+ });
1111
+ }
1112
+ else {
1113
+ customProcDef = Promise.resolve(null);
1114
+ }
1115
+ Promise.all([relationshipsDef, customProcDef]).then(() => {
1116
+ // Interrupt process if progress callback returns `false`
1117
+ if (!itemProgressCallback(template.itemId, common__namespace.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor / 2, createResponse.id)) {
1118
+ itemProgressCallback(template.itemId, common__namespace.EItemProgressStatus.Cancelled, 0);
1119
+ common__namespace
1120
+ .removeItem(createResponse.id, destinationAuthentication)
1121
+ .then(() => resolve(common__namespace.generateEmptyCreationResponse(template.type)), () => resolve(common__namespace.generateEmptyCreationResponse(template.type)));
1122
+ }
1123
+ else {
1124
+ resolve({
1125
+ item: newItemTemplate,
1126
+ id: createResponse.id,
1127
+ type: newItemTemplate.type,
1128
+ postProcess: postProcess
1129
+ });
1130
+ }
1131
+ }, () => {
1132
+ itemProgressCallback(template.itemId, common__namespace.EItemProgressStatus.Failed, 0);
1133
+ resolve(common__namespace.generateEmptyCreationResponse(template.type)); // fails to deploy all resources to the item
1134
+ });
1135
+ }
1136
+ }, () => {
1137
+ itemProgressCallback(template.itemId, common__namespace.EItemProgressStatus.Failed, 0);
1138
+ resolve(common__namespace.generateEmptyCreationResponse(template.type)); // fails to create item
1139
+ });
1140
+ }
1141
+ });
1142
+ }
1184
1143
 
1185
- /** @license
1186
- * Copyright 2020 Esri
1187
- *
1188
- * Licensed under the Apache License, Version 2.0 (the "License");
1189
- * you may not use this file except in compliance with the License.
1190
- * You may obtain a copy of the License at
1191
- *
1192
- * http://www.apache.org/licenses/LICENSE-2.0
1193
- *
1194
- * Unless required by applicable law or agreed to in writing, software
1195
- * distributed under the License is distributed on an "AS IS" BASIS,
1196
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1197
- * See the License for the specific language governing permissions and
1198
- * limitations under the License.
1199
- */
1144
+ /** @license
1145
+ * Copyright 2020 Esri
1146
+ *
1147
+ * Licensed under the Apache License, Version 2.0 (the "License");
1148
+ * you may not use this file except in compliance with the License.
1149
+ * You may obtain a copy of the License at
1150
+ *
1151
+ * http://www.apache.org/licenses/LICENSE-2.0
1152
+ *
1153
+ * Unless required by applicable law or agreed to in writing, software
1154
+ * distributed under the License is distributed on an "AS IS" BASIS,
1155
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1156
+ * See the License for the specific language governing permissions and
1157
+ * limitations under the License.
1158
+ */
1159
+ function updateNotebookData(itemId, data, authentication) {
1160
+ const updateOptions = {
1161
+ id: itemId,
1162
+ data: common.jsonToBlob(data)
1163
+ };
1164
+ return common.updateItem(updateOptions, authentication);
1165
+ }
1200
1166
 
1201
- var notebookHelpers = /*#__PURE__*/Object.freeze({
1202
- __proto__: null,
1203
- createItemFromTemplate: createItemFromTemplate,
1204
- convertItemToTemplate: convertItemToTemplate$7,
1205
- updateNotebookData: updateNotebookData
1206
- });
1167
+ /** @license
1168
+ * Copyright 2020 Esri
1169
+ *
1170
+ * Licensed under the Apache License, Version 2.0 (the "License");
1171
+ * you may not use this file except in compliance with the License.
1172
+ * You may obtain a copy of the License at
1173
+ *
1174
+ * http://www.apache.org/licenses/LICENSE-2.0
1175
+ *
1176
+ * Unless required by applicable law or agreed to in writing, software
1177
+ * distributed under the License is distributed on an "AS IS" BASIS,
1178
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1179
+ * See the License for the specific language governing permissions and
1180
+ * limitations under the License.
1181
+ */
1207
1182
 
1208
- /** @license
1209
- * Copyright 2020 Esri
1210
- *
1211
- * Licensed under the Apache License, Version 2.0 (the "License");
1212
- * you may not use this file except in compliance with the License.
1213
- * You may obtain a copy of the License at
1214
- *
1215
- * http://www.apache.org/licenses/LICENSE-2.0
1216
- *
1217
- * Unless required by applicable law or agreed to in writing, software
1218
- * distributed under the License is distributed on an "AS IS" BASIS,
1219
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1220
- * See the License for the specific language governing permissions and
1221
- * limitations under the License.
1222
- */
1223
- /**
1224
- * Converts a notebook item into a template.
1225
- *
1226
- * @param solutionItemId The solution to contain the template
1227
- * @param itemInfo Info about the item
1228
- * @param authentication Credentials for working with AGO
1229
- * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
1230
- * @return A promise that will resolve when the template has been created
1231
- */
1232
- function convertItemToTemplate$3(solutionItemId, itemInfo, authentication, templateDictionary) {
1233
- // Delegate back to simple-types, which will in-turn delegate
1234
- // to convertNotebookToTemplate at the correct point in the process
1235
- // This is a temporary refactor step
1236
- return convertItemToTemplate$7(solutionItemId, itemInfo, authentication, templateDictionary);
1237
- }
1238
- // Delegate back to simple-types
1239
- // This is a temporary refactor step
1240
- function createItemFromTemplate$1(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
1241
- return createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback);
1242
- }
1243
- /**
1244
- * Converts a Python Notebook item to a template.
1245
- *
1246
- * @param itemTemplate template for the Python Notebook
1247
- * @return templatized itemTemplate
1248
- */
1249
- function convertNotebookToTemplate(itemTemplate) {
1250
- // The templates data to process
1251
- var data = itemTemplate.data;
1252
- var dataString = JSON.stringify(data);
1253
- var idTest = /[0-9A-F]{32}/gim;
1254
- if (data && idTest.test(dataString)) {
1255
- var ids = dataString.match(idTest);
1256
- var verifiedIds_1 = [];
1257
- ids.forEach(function (id) {
1258
- if (verifiedIds_1.indexOf(id) === -1) {
1259
- verifiedIds_1.push(id);
1260
- // templatize the itemId--but only once per unique id
1261
- var regEx = new RegExp(id, "gm");
1262
- dataString = dataString.replace(regEx, "{{" + id + ".itemId}}");
1263
- // update the dependencies
1264
- if (itemTemplate.dependencies.indexOf(id) === -1) {
1265
- itemTemplate.dependencies.push(id);
1266
- }
1267
- }
1268
- });
1269
- itemTemplate.data = JSON.parse(dataString);
1270
- }
1271
- return itemTemplate;
1272
- }
1273
- /**
1274
- * Update the notebooks data
1275
- *
1276
- * @param originalTemplate The original template item
1277
- * @param newlyCreatedItem The current item that may have unswapped variables
1278
- * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
1279
- * @param authentication Credentials for the requests to the destination
1280
- *
1281
- * @return A promise that will resolve once any updates have been made
1282
- */
1283
- function fineTuneCreatedItem$2(originalTemplate, newlyCreatedItem, templateDictionary, authentication) {
1284
- return new Promise(function (resolve, reject) {
1285
- var updateOptions = {
1286
- id: newlyCreatedItem.itemId,
1287
- url: newlyCreatedItem.item.url,
1288
- data: common.jsonToFile(newlyCreatedItem.data, newlyCreatedItem.itemId + ".ipynb")
1289
- };
1290
- common.updateItem(updateOptions, authentication)
1291
- .then(function () { return resolve(null); }, reject);
1292
- });
1293
- }
1294
- /**
1295
- * Notebook specific post-processing actions
1296
- *
1297
- * @param {string} itemId The item ID
1298
- * @param {string} type The template type
1299
- * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects
1300
- * @param {any} templateDictionary The template dictionary
1301
- * @param {UserSession} authentication The destination session info
1302
- * @returns {Promise<any>}
1303
- */
1304
- function postProcess(itemId, type, itemInfos, template, templates, templateDictionary, authentication) {
1305
- return common.updateItemTemplateFromDictionary(itemId, templateDictionary, authentication);
1306
- }
1183
+ var notebookHelpers = /*#__PURE__*/Object.freeze({
1184
+ __proto__: null,
1185
+ createItemFromTemplate: createItemFromTemplate$3,
1186
+ convertItemToTemplate: convertItemToTemplate$1,
1187
+ updateNotebookData: updateNotebookData
1188
+ });
1307
1189
 
1308
- var notebook = /*#__PURE__*/Object.freeze({
1309
- __proto__: null,
1310
- convertItemToTemplate: convertItemToTemplate$3,
1311
- createItemFromTemplate: createItemFromTemplate$1,
1312
- convertNotebookToTemplate: convertNotebookToTemplate,
1313
- fineTuneCreatedItem: fineTuneCreatedItem$2,
1314
- postProcess: postProcess
1315
- });
1190
+ /** @license
1191
+ * Copyright 2020 Esri
1192
+ *
1193
+ * Licensed under the Apache License, Version 2.0 (the "License");
1194
+ * you may not use this file except in compliance with the License.
1195
+ * You may obtain a copy of the License at
1196
+ *
1197
+ * http://www.apache.org/licenses/LICENSE-2.0
1198
+ *
1199
+ * Unless required by applicable law or agreed to in writing, software
1200
+ * distributed under the License is distributed on an "AS IS" BASIS,
1201
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1202
+ * See the License for the specific language governing permissions and
1203
+ * limitations under the License.
1204
+ */
1205
+ /**
1206
+ * Converts a notebook item into a template.
1207
+ *
1208
+ * @param solutionItemId The solution to contain the template
1209
+ * @param itemInfo Info about the item
1210
+ * @param destAuthentication Credentials for requests to the destination organization
1211
+ * @param srcAuthentication Credentials for requests to source items
1212
+ * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
1213
+ * @return A promise that will resolve when the template has been created
1214
+ */
1215
+ function convertItemToTemplate$5(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary) {
1216
+ // Delegate back to simple-types, which will in-turn delegate
1217
+ // to convertNotebookToTemplate at the correct point in the process
1218
+ // This is a temporary refactor step
1219
+ return convertItemToTemplate$1(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary);
1220
+ }
1221
+ // Delegate back to simple-types
1222
+ // This is a temporary refactor step
1223
+ function createItemFromTemplate$2(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
1224
+ return createItemFromTemplate$3(template, templateDictionary, destinationAuthentication, itemProgressCallback);
1225
+ }
1226
+ /**
1227
+ * Converts a Python Notebook item to a template.
1228
+ *
1229
+ * @param itemTemplate template for the Python Notebook
1230
+ * @return templatized itemTemplate
1231
+ */
1232
+ function convertNotebookToTemplate(itemTemplate) {
1233
+ // The templates data to process
1234
+ const data = itemTemplate.data;
1235
+ let dataString = JSON.stringify(data);
1236
+ const idTest = /[0-9A-F]{32}/gim;
1237
+ if (data && idTest.test(dataString)) {
1238
+ const ids = dataString.match(idTest);
1239
+ const verifiedIds = [];
1240
+ ids.forEach(id => {
1241
+ if (verifiedIds.indexOf(id) === -1) {
1242
+ verifiedIds.push(id);
1243
+ // templatize the itemId--but only once per unique id
1244
+ const regEx = new RegExp(id, "gm");
1245
+ dataString = dataString.replace(regEx, "{{" + id + ".itemId}}");
1246
+ // update the dependencies
1247
+ if (itemTemplate.dependencies.indexOf(id) === -1) {
1248
+ itemTemplate.dependencies.push(id);
1249
+ }
1250
+ }
1251
+ });
1252
+ itemTemplate.data = JSON.parse(dataString);
1253
+ }
1254
+ return itemTemplate;
1255
+ }
1256
+ /**
1257
+ * Update the notebooks data
1258
+ *
1259
+ * @param originalTemplate The original template item
1260
+ * @param newlyCreatedItem The current item that may have unswapped variables
1261
+ * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
1262
+ * @param authentication Credentials for the requests to the destination
1263
+ *
1264
+ * @return A promise that will resolve once any updates have been made
1265
+ */
1266
+ function fineTuneCreatedItem(originalTemplate, newlyCreatedItem, templateDictionary, authentication) {
1267
+ return new Promise((resolve, reject) => {
1268
+ const updateOptions = {
1269
+ id: newlyCreatedItem.itemId,
1270
+ url: newlyCreatedItem.item.url,
1271
+ data: common__namespace.jsonToFile(newlyCreatedItem.data, newlyCreatedItem.itemId + ".ipynb")
1272
+ };
1273
+ common__namespace
1274
+ .updateItem(updateOptions, authentication)
1275
+ .then(() => resolve(null), reject);
1276
+ });
1277
+ }
1278
+ /**
1279
+ * Notebook specific post-processing actions
1280
+ *
1281
+ * @param {string} itemId The item ID
1282
+ * @param {string} type The template type
1283
+ * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects
1284
+ * @param {any} templateDictionary The template dictionary
1285
+ * @param {UserSession} authentication The destination session info
1286
+ * @returns {Promise<any>}
1287
+ */
1288
+ function postProcess$2(itemId, type, itemInfos, template, templates, templateDictionary, authentication) {
1289
+ return common__namespace.updateItemTemplateFromDictionary(itemId, templateDictionary, authentication);
1290
+ }
1316
1291
 
1317
- /** @license
1318
- * Copyright 2018 Esri
1319
- *
1320
- * Licensed under the Apache License, Version 2.0 (the "License");
1321
- * you may not use this file except in compliance with the License.
1322
- * You may obtain a copy of the License at
1323
- *
1324
- * http://www.apache.org/licenses/LICENSE-2.0
1325
- *
1326
- * Unless required by applicable law or agreed to in writing, software
1327
- * distributed under the License is distributed on an "AS IS" BASIS,
1328
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1329
- * See the License for the specific language governing permissions and
1330
- * limitations under the License.
1331
- */
1332
- // ------------------------------------------------------------------------------------------------------------------ //
1333
- /**
1334
- * Converts an AGOL OIC (Oriented Imagery Catalog) item to a template.
1335
- *
1336
- * @param itemTemplate Template for the OIC (Oriented Imagery Catalog) item
1337
- * @param authentication credentials for the request
1338
- * @return Template for the solution item that contains key details for item reconstruction
1339
- */
1340
- function convertItemToTemplate$4(itemTemplate, authentication) {
1341
- return new Promise(function (resolve, reject) {
1342
- // Extract dependencies
1343
- _extractDependencies$2(itemTemplate, authentication).then(function (results) {
1344
- var _a;
1345
- itemTemplate.dependencies = results.dependencies;
1346
- // Templatize the map layer ids after we've extracted them as dependencies
1347
- /* istanbul ignore else */
1348
- if ((_a = itemTemplate.data) === null || _a === void 0 ? void 0 : _a.properties) {
1349
- itemTemplate.data.properties.ServiceURL = _templatizeOicLayerUrl(itemTemplate.data.properties.ServiceURL, results.urlHash);
1350
- itemTemplate.data.properties.OverviewURL = _templatizeOicLayerUrl(itemTemplate.data.properties.OverviewURL, results.urlHash);
1351
- }
1352
- resolve(itemTemplate);
1353
- }, function (e) { return reject(common.fail(e)); });
1354
- });
1355
- }
1356
- /**
1357
- * Gets the ids of the dependencies of an AGOL OIC (Oriented Imagery Catalog) item.
1358
- *
1359
- * @param itemTemplate A OIC (Oriented Imagery Catalog) item whose dependencies are sought
1360
- * @param authentication Credentials for any requests
1361
- * @return List of dependencies ids and url/itemId hash
1362
- * @protected
1363
- */
1364
- function _extractDependencies$2(itemTemplate, authentication) {
1365
- return new Promise(function (resolve, reject) {
1366
- var _a;
1367
- var dependencies = [];
1368
- if ((_a = itemTemplate.data) === null || _a === void 0 ? void 0 : _a.properties) {
1369
- var layerURLs = [];
1370
- /* istanbul ignore else */
1371
- if (itemTemplate.data.properties.ServiceURL) {
1372
- layerURLs.push(itemTemplate.data.properties.ServiceURL);
1373
- }
1374
- /* istanbul ignore else */
1375
- if (itemTemplate.data.properties.OverviewURL &&
1376
- itemTemplate.data.properties.OverviewURL !==
1377
- itemTemplate.data.properties.ServiceURL) {
1378
- layerURLs.push(itemTemplate.data.properties.OverviewURL);
1379
- }
1380
- _getLayerIds(layerURLs, dependencies, authentication).then(function (results) {
1381
- resolve(results);
1382
- }, function (e) { return reject(common.fail(e)); });
1383
- }
1384
- else {
1385
- resolve({
1386
- dependencies: dependencies,
1387
- urlHash: {}
1388
- });
1389
- }
1390
- });
1391
- }
1392
- /**
1393
- * Extracts the AGOL itemId for each layer in a list using the url.
1394
- *
1395
- * @param layerURLs List of OIC layer URLs
1396
- * @param dependencies Current list of dependencies
1397
- * @param authentication Credentials for any requests
1398
- * @return List of dependencies ids and url/itemId hash
1399
- * @protected
1400
- */
1401
- function _getLayerIds(layerURLs, dependencies, authentication) {
1402
- return new Promise(function (resolve, reject) {
1403
- var urlHash = {};
1404
- var options = {
1405
- f: "json",
1406
- authentication: authentication
1407
- };
1408
- var layerPromises = [];
1409
- var layerChecks = {};
1410
- var filteredLayerURLs = layerURLs.filter(function (layerURL) {
1411
- if (layerURL) {
1412
- var results = /.+FeatureServer/g.exec(layerURL);
1413
- var baseUrl = Array.isArray(results) && results.length > 0 ? results[0] : undefined;
1414
- if (baseUrl) {
1415
- // avoid redundant checks when we have a layer with subLayers
1416
- /* istanbul ignore else */
1417
- if (Object.keys(layerChecks).indexOf(baseUrl) < 0) {
1418
- layerChecks[baseUrl] = common.rest_request(layerURL, options);
1419
- }
1420
- layerPromises.push(layerChecks[baseUrl]);
1421
- return true;
1422
- }
1423
- else {
1424
- return false;
1425
- }
1426
- }
1427
- else {
1428
- return false;
1429
- }
1430
- });
1431
- if (layerPromises.length > 0) {
1432
- Promise.all(layerPromises).then(function (serviceResponses) {
1433
- serviceResponses.forEach(function (serviceResponse, i) {
1434
- /* istanbul ignore else */
1435
- if (common.getProp(serviceResponse, "serviceItemId")) {
1436
- var id = serviceResponse.serviceItemId;
1437
- /* istanbul ignore else */
1438
- if (dependencies.indexOf(id) < 0) {
1439
- dependencies.push(id);
1440
- }
1441
- urlHash[filteredLayerURLs[i]] = id;
1442
- }
1443
- });
1444
- resolve({
1445
- dependencies: dependencies,
1446
- urlHash: urlHash
1447
- });
1448
- }, function (e) { return reject(common.fail(e)); });
1449
- }
1450
- else {
1451
- resolve({
1452
- dependencies: dependencies,
1453
- urlHash: urlHash
1454
- });
1455
- }
1456
- });
1457
- }
1458
- /**
1459
- * Templatizes the url and item id for a layer.
1460
- *
1461
- * @param layerURL OIC layer URL
1462
- * @param urlHash Lookup object for analysis layers
1463
- * @return Templatized URL if layerURL is in the urlHash
1464
- * @protected
1465
- */
1466
- function _templatizeOicLayerUrl(layerURL, urlHash) {
1467
- var templatizedURL = layerURL;
1468
- if (layerURL) {
1469
- var id = urlHash[layerURL];
1470
- if (id) {
1471
- var layerId = layerURL.substr(layerURL.lastIndexOf("/") + 1);
1472
- templatizedURL = common.templatizeTerm(id, id, ".layer" + layerId + ".url");
1473
- }
1474
- }
1475
- return templatizedURL;
1476
- }
1292
+ var notebook = /*#__PURE__*/Object.freeze({
1293
+ __proto__: null,
1294
+ convertItemToTemplate: convertItemToTemplate$5,
1295
+ createItemFromTemplate: createItemFromTemplate$2,
1296
+ convertNotebookToTemplate: convertNotebookToTemplate,
1297
+ fineTuneCreatedItem: fineTuneCreatedItem,
1298
+ postProcess: postProcess$2
1299
+ });
1477
1300
 
1478
- /** @license
1479
- * Copyright 2020 Esri
1480
- *
1481
- * Licensed under the Apache License, Version 2.0 (the "License");
1482
- * you may not use this file except in compliance with the License.
1483
- * You may obtain a copy of the License at
1484
- *
1485
- * http://www.apache.org/licenses/LICENSE-2.0
1486
- *
1487
- * Unless required by applicable law or agreed to in writing, software
1488
- * distributed under the License is distributed on an "AS IS" BASIS,
1489
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1490
- * See the License for the specific language governing permissions and
1491
- * limitations under the License.
1492
- */
1301
+ /** @license
1302
+ * Copyright 2018 Esri
1303
+ *
1304
+ * Licensed under the Apache License, Version 2.0 (the "License");
1305
+ * you may not use this file except in compliance with the License.
1306
+ * You may obtain a copy of the License at
1307
+ *
1308
+ * http://www.apache.org/licenses/LICENSE-2.0
1309
+ *
1310
+ * Unless required by applicable law or agreed to in writing, software
1311
+ * distributed under the License is distributed on an "AS IS" BASIS,
1312
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
+ * See the License for the specific language governing permissions and
1314
+ * limitations under the License.
1315
+ */
1316
+ // ------------------------------------------------------------------------------------------------------------------ //
1317
+ /**
1318
+ * Converts an AGOL OIC (Oriented Imagery Catalog) item to a template.
1319
+ *
1320
+ * @param itemTemplate Template for the OIC (Oriented Imagery Catalog) item
1321
+ * @param destAuthentication Credentials for requests to the destination organization
1322
+ * @param srcAuthentication Credentials for requests to source items
1323
+ * @return Template for the solution item that contains key details for item reconstruction
1324
+ */
1325
+ function convertItemToTemplate$4(itemTemplate, destAuthentication, srcAuthentication) {
1326
+ return new Promise((resolve, reject) => {
1327
+ // Extract dependencies
1328
+ _extractDependencies$1(itemTemplate, srcAuthentication).then((results) => {
1329
+ itemTemplate.dependencies = results.dependencies;
1330
+ // Templatize the map layer ids after we've extracted them as dependencies
1331
+ /* istanbul ignore else */
1332
+ if (itemTemplate.data?.properties) {
1333
+ itemTemplate.data.properties.ServiceURL = _templatizeOicLayerUrl(itemTemplate.data.properties.ServiceURL, results.urlHash);
1334
+ itemTemplate.data.properties.OverviewURL = _templatizeOicLayerUrl(itemTemplate.data.properties.OverviewURL, results.urlHash);
1335
+ }
1336
+ resolve(itemTemplate);
1337
+ }, e => reject(common__namespace.fail(e)));
1338
+ });
1339
+ }
1340
+ /**
1341
+ * Gets the ids of the dependencies of an AGOL OIC (Oriented Imagery Catalog) item.
1342
+ *
1343
+ * @param itemTemplate A OIC (Oriented Imagery Catalog) item whose dependencies are sought
1344
+ * @param authentication Credentials for any requests
1345
+ * @return List of dependencies ids and url/itemId hash
1346
+ * @protected
1347
+ */
1348
+ function _extractDependencies$1(itemTemplate, authentication) {
1349
+ return new Promise((resolve, reject) => {
1350
+ const dependencies = [];
1351
+ if (itemTemplate.data?.properties) {
1352
+ const layerURLs = [];
1353
+ /* istanbul ignore else */
1354
+ if (itemTemplate.data.properties.ServiceURL) {
1355
+ layerURLs.push(itemTemplate.data.properties.ServiceURL);
1356
+ }
1357
+ /* istanbul ignore else */
1358
+ if (itemTemplate.data.properties.OverviewURL &&
1359
+ itemTemplate.data.properties.OverviewURL !==
1360
+ itemTemplate.data.properties.ServiceURL) {
1361
+ layerURLs.push(itemTemplate.data.properties.OverviewURL);
1362
+ }
1363
+ _getLayerIds$1(layerURLs, dependencies, authentication).then(results => {
1364
+ resolve(results);
1365
+ }, e => reject(common__namespace.fail(e)));
1366
+ }
1367
+ else {
1368
+ resolve({
1369
+ dependencies: dependencies,
1370
+ urlHash: {}
1371
+ });
1372
+ }
1373
+ });
1374
+ }
1375
+ /**
1376
+ * Extracts the AGOL itemId for each layer in a list using the url.
1377
+ *
1378
+ * @param layerURLs List of OIC layer URLs
1379
+ * @param dependencies Current list of dependencies
1380
+ * @param authentication Credentials for any requests
1381
+ * @return List of dependencies ids and url/itemId hash
1382
+ * @protected
1383
+ */
1384
+ function _getLayerIds$1(layerURLs, dependencies, authentication) {
1385
+ return new Promise((resolve, reject) => {
1386
+ const urlHash = {};
1387
+ const options = {
1388
+ f: "json",
1389
+ authentication: authentication
1390
+ };
1391
+ const layerPromises = [];
1392
+ const layerChecks = {};
1393
+ const filteredLayerURLs = layerURLs.filter(layerURL => {
1394
+ if (layerURL) {
1395
+ const results = /.+FeatureServer/g.exec(layerURL);
1396
+ const baseUrl = Array.isArray(results) && results.length > 0 ? results[0] : undefined;
1397
+ if (baseUrl) {
1398
+ // avoid redundant checks when we have a layer with subLayers
1399
+ /* istanbul ignore else */
1400
+ if (Object.keys(layerChecks).indexOf(baseUrl) < 0) {
1401
+ layerChecks[baseUrl] = common__namespace.rest_request(layerURL, options);
1402
+ }
1403
+ layerPromises.push(layerChecks[baseUrl]);
1404
+ return true;
1405
+ }
1406
+ else {
1407
+ return false;
1408
+ }
1409
+ }
1410
+ else {
1411
+ return false;
1412
+ }
1413
+ });
1414
+ if (layerPromises.length > 0) {
1415
+ Promise.all(layerPromises).then(serviceResponses => {
1416
+ serviceResponses.forEach((serviceResponse, i) => {
1417
+ /* istanbul ignore else */
1418
+ if (common__namespace.getProp(serviceResponse, "serviceItemId")) {
1419
+ const id = serviceResponse.serviceItemId;
1420
+ /* istanbul ignore else */
1421
+ if (dependencies.indexOf(id) < 0) {
1422
+ dependencies.push(id);
1423
+ }
1424
+ urlHash[filteredLayerURLs[i]] = id;
1425
+ }
1426
+ });
1427
+ resolve({
1428
+ dependencies: dependencies,
1429
+ urlHash: urlHash
1430
+ });
1431
+ }, e => reject(common__namespace.fail(e)));
1432
+ }
1433
+ else {
1434
+ resolve({
1435
+ dependencies: dependencies,
1436
+ urlHash: urlHash
1437
+ });
1438
+ }
1439
+ });
1440
+ }
1441
+ /**
1442
+ * Templatizes the url and item id for a layer.
1443
+ *
1444
+ * @param layerURL OIC layer URL
1445
+ * @param urlHash Lookup object for analysis layers
1446
+ * @return Templatized URL if layerURL is in the urlHash
1447
+ * @protected
1448
+ */
1449
+ function _templatizeOicLayerUrl(layerURL, urlHash) {
1450
+ let templatizedURL = layerURL;
1451
+ if (layerURL) {
1452
+ const id = urlHash[layerURL];
1453
+ if (id) {
1454
+ const layerId = layerURL.substr(layerURL.lastIndexOf("/") + 1);
1455
+ templatizedURL = common__namespace.templatizeTerm(id, id, ".layer" + layerId + ".url");
1456
+ }
1457
+ // replace everything up until /home with portalBaseUrl var and templatize the itemId
1458
+ templatizedURL = common__namespace.templatizeIds(templatizedURL.replace(/.+?(?=\/home)/, "{{portalBaseUrl}}"));
1459
+ }
1460
+ return templatizedURL;
1461
+ }
1493
1462
 
1494
- var quickcaptureHelpers = /*#__PURE__*/Object.freeze({
1495
- __proto__: null,
1496
- createItemFromTemplate: createItemFromTemplate,
1497
- convertItemToTemplate: convertItemToTemplate$7
1498
- });
1463
+ /** @license
1464
+ * Copyright 2020 Esri
1465
+ *
1466
+ * Licensed under the Apache License, Version 2.0 (the "License");
1467
+ * you may not use this file except in compliance with the License.
1468
+ * You may obtain a copy of the License at
1469
+ *
1470
+ * http://www.apache.org/licenses/LICENSE-2.0
1471
+ *
1472
+ * Unless required by applicable law or agreed to in writing, software
1473
+ * distributed under the License is distributed on an "AS IS" BASIS,
1474
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1475
+ * See the License for the specific language governing permissions and
1476
+ * limitations under the License.
1477
+ */
1499
1478
 
1500
- /** @license
1501
- * Copyright 2018 Esri
1502
- *
1503
- * Licensed under the Apache License, Version 2.0 (the "License");
1504
- * you may not use this file except in compliance with the License.
1505
- * You may obtain a copy of the License at
1506
- *
1507
- * http://www.apache.org/licenses/LICENSE-2.0
1508
- *
1509
- * Unless required by applicable law or agreed to in writing, software
1510
- * distributed under the License is distributed on an "AS IS" BASIS,
1511
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1512
- * See the License for the specific language governing permissions and
1513
- * limitations under the License.
1514
- */
1515
- //#region Publish Process ---------------------------------------------------------------------------------------//
1516
- /**
1517
- * Converts a Quick Capture item into a template.
1518
- *
1519
- * @param solutionItemId The solution to contain the template
1520
- * @param itemInfo Info about the item
1521
- * @param authentication Credentials for working with AGO
1522
- * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
1523
- * @return A promise that will resolve when the template has been created
1524
- */
1525
- function convertItemToTemplate$5(solutionItemId, itemInfo, authentication, templateDictionary) {
1526
- // Delegate back to simple-types, which will in-turn delegate
1527
- // to convertNotebookToTemplate at the correct point in the process
1528
- // This is a temporary refactor step
1529
- return convertItemToTemplate$7(solutionItemId, itemInfo, authentication, templateDictionary);
1530
- }
1531
- /**
1532
- * Converts an quick capture item to a template.
1533
- *
1534
- * @param itemTemplate template for the quick capture project item
1535
- * @return templatized itemTemplate
1536
- */
1537
- function convertQuickCaptureToTemplate(itemTemplate) {
1538
- return new Promise(function (resolve, reject) {
1539
- // The templates data to process
1540
- var data = itemTemplate.data;
1541
- if (data && Array.isArray(data)) {
1542
- var applicationRequest_1 = Promise.resolve(null);
1543
- var applicationName_1 = "";
1544
- data.some(function (item) {
1545
- if (item.type === "application/json") {
1546
- applicationName_1 = item.name;
1547
- applicationRequest_1 = common.getBlobText(item);
1548
- return true;
1549
- }
1550
- });
1551
- applicationRequest_1.then(function (result) {
1552
- // replace the template data array with the templatized application JSON
1553
- itemTemplate.data = result
1554
- ? {
1555
- application: _templatizeApplication(JSON.parse(result), itemTemplate),
1556
- name: applicationName_1
1557
- }
1558
- : {};
1559
- resolve(itemTemplate);
1560
- }, reject);
1561
- }
1562
- else {
1563
- resolve(itemTemplate);
1564
- }
1565
- });
1566
- }
1567
- /**
1568
- * Templatizes key properties for a quick capture project and gathers item dependencies
1569
- *
1570
- * @param data the projects json
1571
- * @param itemTemplate template for the quick capture project item
1572
- * @return templatized itemTemplate
1573
- */
1574
- function _templatizeApplication(data, itemTemplate) {
1575
- // Quick Project item id
1576
- _templatizeId(data, "itemId");
1577
- // Set the admin email
1578
- _templatizeAdminEmail(data);
1579
- // datasource item id and url
1580
- var dataSources = data.dataSources;
1581
- if (dataSources && Array.isArray(dataSources)) {
1582
- dataSources.forEach(function (ds) {
1583
- var id = ds.featureServiceItemId;
1584
- if (id) {
1585
- _updateDependencies(id, itemTemplate);
1586
- _templatizeUrl(ds, "featureServiceItemId", "url");
1587
- _templatizeId(ds, "featureServiceItemId");
1588
- }
1589
- });
1590
- }
1591
- return data;
1592
- }
1593
- /**
1594
- * Templatize the email property
1595
- *
1596
- * @param data the quick capture application
1597
- */
1598
- function _templatizeAdminEmail(data) {
1599
- if (common.getProp(data, "preferences.adminEmail")) {
1600
- common.setProp(data, "preferences.adminEmail", "{{user.email}}");
1601
- }
1602
- }
1603
- /**
1604
- * Updates the templates dependencies list with unique item ids
1605
- *
1606
- * @param id the item id of the dependency
1607
- * @param itemTemplate template for the quick capture project item
1608
- * @return templatized itemTemplate
1609
- */
1610
- function _updateDependencies(id, itemTemplate) {
1611
- if (itemTemplate.dependencies.indexOf(id) === -1) {
1612
- itemTemplate.dependencies.push(id);
1613
- }
1614
- }
1615
- /**
1616
- * Templatize a url property
1617
- *
1618
- * @param obj the datasource object
1619
- * @param idPath the path to the id property
1620
- * @param urlPath the path to the url property
1621
- */
1622
- function _templatizeUrl(obj, idPath, urlPath) {
1623
- var id = common.getProp(obj, idPath);
1624
- var url = common.getProp(obj, urlPath);
1625
- if (url) {
1626
- var layerId = url.substr(url.lastIndexOf("/") + 1);
1627
- common.setProp(obj, urlPath, common.templatizeTerm(id, id, ".layer" + layerId + ".url"));
1628
- }
1629
- }
1630
- /**
1631
- * Templatize the item id property
1632
- *
1633
- * @param obj the datasource or object that contains the item id property
1634
- * @param path the path to the id property
1635
- */
1636
- function _templatizeId(obj, path) {
1637
- var id = common.getProp(obj, path);
1638
- if (id) {
1639
- common.setProp(obj, path, common.templatizeTerm(id, id, ".itemId"));
1640
- }
1641
- }
1642
- //#endregion
1643
- //#region Deploy Process ---------------------------------------------------------------------------------------//
1644
- // Delegate back to simple-types
1645
- // This is a temporary refactor step
1646
- function createItemFromTemplate$2(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
1647
- return createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback);
1648
- }
1649
- /**
1650
- * QuickCapture post-processing actions
1651
- *
1652
- * @param {string} itemId The item ID
1653
- * @param {string} type The template type
1654
- * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects
1655
- * @param {any} templateDictionary The template dictionary
1656
- * @param {UserSession} authentication The destination session info
1657
- * @returns Promise resolving to successfulness of update
1658
- */
1659
- function postProcess$1(itemId, type, itemInfos, template, templates, templateDictionary, authentication) {
1660
- return new Promise(function (resolve, reject) {
1661
- template.data = common.replaceInTemplate(template.data, templateDictionary);
1662
- common.updateItemTemplateFromDictionary(itemId, templateDictionary, authentication)
1663
- .then(function () {
1664
- common.updateItemResourceText(itemId, template.data.name, JSON.stringify(template.data.application), authentication)
1665
- .then(resolve, reject);
1666
- }, reject);
1667
- });
1668
- }
1669
- //#endregion
1479
+ var quickcaptureHelpers = /*#__PURE__*/Object.freeze({
1480
+ __proto__: null,
1481
+ createItemFromTemplate: createItemFromTemplate$3,
1482
+ convertItemToTemplate: convertItemToTemplate$1
1483
+ });
1670
1484
 
1671
- var quickcapture = /*#__PURE__*/Object.freeze({
1672
- __proto__: null,
1673
- convertItemToTemplate: convertItemToTemplate$5,
1674
- convertQuickCaptureToTemplate: convertQuickCaptureToTemplate,
1675
- _templatizeApplication: _templatizeApplication,
1676
- _templatizeAdminEmail: _templatizeAdminEmail,
1677
- _updateDependencies: _updateDependencies,
1678
- _templatizeUrl: _templatizeUrl,
1679
- _templatizeId: _templatizeId,
1680
- createItemFromTemplate: createItemFromTemplate$2,
1681
- postProcess: postProcess$1
1682
- });
1485
+ /** @license
1486
+ * Copyright 2018 Esri
1487
+ *
1488
+ * Licensed under the Apache License, Version 2.0 (the "License");
1489
+ * you may not use this file except in compliance with the License.
1490
+ * You may obtain a copy of the License at
1491
+ *
1492
+ * http://www.apache.org/licenses/LICENSE-2.0
1493
+ *
1494
+ * Unless required by applicable law or agreed to in writing, software
1495
+ * distributed under the License is distributed on an "AS IS" BASIS,
1496
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1497
+ * See the License for the specific language governing permissions and
1498
+ * limitations under the License.
1499
+ */
1500
+ //#region Publish Process ---------------------------------------------------------------------------------------//
1501
+ /**
1502
+ * Converts a Quick Capture item into a template.
1503
+ *
1504
+ * @param solutionItemId The solution to contain the template
1505
+ * @param itemInfo Info about the item
1506
+ * @param destAuthentication Credentials for requests to the destination organization
1507
+ * @param srcAuthentication Credentials for requests to source items
1508
+ * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
1509
+ * @return A promise that will resolve when the template has been created
1510
+ */
1511
+ function convertItemToTemplate$3(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary) {
1512
+ // Delegate back to simple-types, which will in-turn delegate
1513
+ // to convertNotebookToTemplate at the correct point in the process
1514
+ // This is a temporary refactor step
1515
+ return convertItemToTemplate$1(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary);
1516
+ }
1517
+ /**
1518
+ * Converts an quick capture item to a template.
1519
+ *
1520
+ * @param itemTemplate template for the quick capture project item
1521
+ * @return templatized itemTemplate
1522
+ */
1523
+ function convertQuickCaptureToTemplate(itemTemplate) {
1524
+ return new Promise((resolve, reject) => {
1525
+ // The templates data to process
1526
+ const data = itemTemplate.data;
1527
+ if (data && Array.isArray(data)) {
1528
+ let applicationRequest = Promise.resolve(null);
1529
+ let applicationName = "";
1530
+ data.some((item) => {
1531
+ if (item.type === "application/json") {
1532
+ applicationName = item.name;
1533
+ applicationRequest = common__namespace.getBlobText(item);
1534
+ return true;
1535
+ }
1536
+ });
1537
+ applicationRequest.then(result => {
1538
+ // replace the template data array with the templatized application JSON
1539
+ itemTemplate.data = result
1540
+ ? {
1541
+ application: _templatizeApplication(JSON.parse(result), itemTemplate),
1542
+ name: applicationName
1543
+ }
1544
+ : {};
1545
+ resolve(itemTemplate);
1546
+ }, reject);
1547
+ }
1548
+ else {
1549
+ resolve(itemTemplate);
1550
+ }
1551
+ });
1552
+ }
1553
+ /**
1554
+ * Templatizes key properties for a quick capture project and gathers item dependencies
1555
+ *
1556
+ * @param data the projects json
1557
+ * @param itemTemplate template for the quick capture project item
1558
+ * @return templatized itemTemplate
1559
+ */
1560
+ function _templatizeApplication(data, itemTemplate) {
1561
+ // Quick Project item id
1562
+ _templatizeId(data, "itemId");
1563
+ // Set the admin email
1564
+ _templatizeAdminEmail(data);
1565
+ // datasource item id and url
1566
+ const dataSources = data.dataSources;
1567
+ if (dataSources && Array.isArray(dataSources)) {
1568
+ dataSources.forEach(ds => {
1569
+ const id = ds.featureServiceItemId;
1570
+ if (id) {
1571
+ _updateDependencies(id, itemTemplate);
1572
+ _templatizeUrl(ds, "featureServiceItemId", "url");
1573
+ _templatizeId(ds, "featureServiceItemId");
1574
+ }
1575
+ });
1576
+ }
1577
+ return data;
1578
+ }
1579
+ /**
1580
+ * Templatize the email property
1581
+ *
1582
+ * @param data the quick capture application
1583
+ */
1584
+ function _templatizeAdminEmail(data) {
1585
+ if (common__namespace.getProp(data, "preferences.adminEmail")) {
1586
+ common__namespace.setProp(data, "preferences.adminEmail", "{{user.email}}");
1587
+ }
1588
+ }
1589
+ /**
1590
+ * Updates the templates dependencies list with unique item ids
1591
+ *
1592
+ * @param id the item id of the dependency
1593
+ * @param itemTemplate template for the quick capture project item
1594
+ * @return templatized itemTemplate
1595
+ */
1596
+ function _updateDependencies(id, itemTemplate) {
1597
+ if (itemTemplate.dependencies.indexOf(id) === -1) {
1598
+ itemTemplate.dependencies.push(id);
1599
+ }
1600
+ }
1601
+ /**
1602
+ * Templatize a url property
1603
+ *
1604
+ * @param obj the datasource object
1605
+ * @param idPath the path to the id property
1606
+ * @param urlPath the path to the url property
1607
+ */
1608
+ function _templatizeUrl(obj, idPath, urlPath) {
1609
+ const id = common__namespace.getProp(obj, idPath);
1610
+ const url = common__namespace.getProp(obj, urlPath);
1611
+ if (url) {
1612
+ const layerId = url.substr(url.lastIndexOf("/") + 1);
1613
+ common__namespace.setProp(obj, urlPath, common__namespace.templatizeTerm(id, id, ".layer" + layerId + ".url"));
1614
+ }
1615
+ }
1616
+ /**
1617
+ * Templatize the item id property
1618
+ *
1619
+ * @param obj the datasource or object that contains the item id property
1620
+ * @param path the path to the id property
1621
+ */
1622
+ function _templatizeId(obj, path) {
1623
+ const id = common__namespace.getProp(obj, path);
1624
+ if (id) {
1625
+ common__namespace.setProp(obj, path, common__namespace.templatizeTerm(id, id, ".itemId"));
1626
+ }
1627
+ }
1628
+ //#endregion
1629
+ //#region Deploy Process ---------------------------------------------------------------------------------------//
1630
+ // Delegate back to simple-types
1631
+ // This is a temporary refactor step
1632
+ function createItemFromTemplate$1(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
1633
+ return createItemFromTemplate$3(template, templateDictionary, destinationAuthentication, itemProgressCallback);
1634
+ }
1635
+ /**
1636
+ * QuickCapture post-processing actions
1637
+ *
1638
+ * @param {string} itemId The item ID
1639
+ * @param {string} type The template type
1640
+ * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects
1641
+ * @param {any} templateDictionary The template dictionary
1642
+ * @param {UserSession} authentication The destination session info
1643
+ * @returns Promise resolving to successfulness of update
1644
+ */
1645
+ function postProcess$1(itemId, type, itemInfos, template, templates, templateDictionary, authentication) {
1646
+ return new Promise((resolve, reject) => {
1647
+ template.data = common__namespace.replaceInTemplate(template.data, templateDictionary);
1648
+ common__namespace
1649
+ .updateItemTemplateFromDictionary(itemId, templateDictionary, authentication)
1650
+ .then(() => {
1651
+ common__namespace
1652
+ .updateItemResourceText(itemId, template.data.name, JSON.stringify(template.data.application), authentication)
1653
+ .then(resolve, reject);
1654
+ }, reject);
1655
+ });
1656
+ }
1657
+ //#endregion
1683
1658
 
1684
- /** @license
1685
- * Copyright 2018 Esri
1686
- *
1687
- * Licensed under the Apache License, Version 2.0 (the "License");
1688
- * you may not use this file except in compliance with the License.
1689
- * You may obtain a copy of the License at
1690
- *
1691
- * http://www.apache.org/licenses/LICENSE-2.0
1692
- *
1693
- * Unless required by applicable law or agreed to in writing, software
1694
- * distributed under the License is distributed on an "AS IS" BASIS,
1695
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1696
- * See the License for the specific language governing permissions and
1697
- * limitations under the License.
1698
- */
1699
- /**
1700
- * The portion of a Webmap URL between the server and the map id.
1701
- *
1702
- * @protected
1703
- */
1704
- var WEBMAP_APP_URL_PART = "home/webmap/viewer.html?webmap=";
1705
- // ------------------------------------------------------------------------------------------------------------------ //
1706
- /**
1707
- * Converts an AGOL webmap item to a template.
1708
- *
1709
- * @param itemTemplate Template for the webmap item
1710
- * @param authentication credentials for the request
1711
- * @return Template for the solution item that contains key details for item reconstruction
1712
- */
1713
- function convertItemToTemplate$6(itemTemplate, authentication) {
1714
- return new Promise(function (resolve, reject) {
1715
- // Templatize the app URL
1716
- itemTemplate.item.url =
1717
- common.checkUrlPathTermination(common.placeholder(common.SERVER_NAME)) +
1718
- WEBMAP_APP_URL_PART +
1719
- itemTemplate.item.id; // templatized id
1720
- // Extract dependencies
1721
- _extractDependencies$3(itemTemplate, authentication).then(function (results) {
1722
- itemTemplate.dependencies = results.dependencies;
1723
- // Templatize the map layer ids after we've extracted them as dependencies
1724
- if (itemTemplate.data) {
1725
- _templatizeWebmapLayerIdsAndUrls(itemTemplate.data.operationalLayers, results.urlHash);
1726
- _templatizeWebmapLayerIdsAndUrls(itemTemplate.data.tables, results.urlHash);
1727
- // Exclude intialState
1728
- _excludeInitialState(itemTemplate.data);
1729
- }
1730
- resolve(itemTemplate);
1731
- }, function (e) { return reject(common.fail(e)); });
1732
- });
1733
- }
1734
- /**
1735
- * Gets the ids of the dependencies of an AGOL webmap item.
1736
- *
1737
- * @param itemTemplate A webmap item whose dependencies are sought
1738
- * @param authentication Credentials for any requests
1739
- * @return List of dependencies ids and url/itemId hash
1740
- * @protected
1741
- */
1742
- function _extractDependencies$3(itemTemplate, authentication) {
1743
- return new Promise(function (resolve, reject) {
1744
- var dependencies = [];
1745
- if (itemTemplate.data) {
1746
- var layers = itemTemplate.data.operationalLayers || [];
1747
- var tables = itemTemplate.data.tables || [];
1748
- var layersAndTables = layers.concat(tables);
1749
- _getLayerIds$1(layersAndTables, dependencies, authentication).then(function (results) {
1750
- resolve(results);
1751
- }, function (e) { return reject(common.fail(e)); });
1752
- }
1753
- else {
1754
- resolve({
1755
- dependencies: dependencies,
1756
- urlHash: {}
1757
- });
1758
- }
1759
- });
1760
- }
1761
- /**
1762
- * Remove the initialState prop from webmaps saved from the new map viewer.
1763
- * This allows the map to use the item extent property that we templatize.
1764
- *
1765
- * Added for issue #662
1766
- *
1767
- * @param data the data for the web maps item template
1768
- * @return void
1769
- * @protected
1770
- */
1771
- function _excludeInitialState(data) {
1772
- common.deleteProp(data, "initialState");
1773
- }
1774
- /**
1775
- * Extracts the AGOL itemId for each layer or table object in a list using the url.
1776
- *
1777
- * @param layerList List of map layers or tables
1778
- * @param dependencies Current list of dependencies
1779
- * @param authentication Credentials for any requests
1780
- * @return List of dependencies ids and url/itemId hash
1781
- * @protected
1782
- */
1783
- function _getLayerIds$1(layerList, dependencies, authentication) {
1784
- return new Promise(function (resolve, reject) {
1785
- var urlHash = {};
1786
- var options = {
1787
- f: "json",
1788
- authentication: authentication
1789
- };
1790
- var layerPromises = [];
1791
- var layerChecks = {};
1792
- var layers = layerList.filter(function (layer) {
1793
- if (layer.url && layer.url.indexOf("{{velocityUrl}}") < 0) {
1794
- var results = /.+FeatureServer/g.exec(layer.url);
1795
- var baseUrl = Array.isArray(results) && results.length > 0 ? results[0] : undefined;
1796
- if (baseUrl) {
1797
- // avoid redundant checks when we have a layer with subLayers
1798
- if (Object.keys(layerChecks).indexOf(baseUrl) < 0) {
1799
- layerChecks[baseUrl] = common.rest_request(layer.url, options);
1800
- }
1801
- layerPromises.push(layerChecks[baseUrl]);
1802
- return true;
1803
- }
1804
- else {
1805
- return false;
1806
- }
1807
- }
1808
- else {
1809
- return false;
1810
- }
1811
- });
1812
- if (layerPromises.length > 0) {
1813
- Promise.all(layerPromises).then(function (serviceResponses) {
1814
- serviceResponses.forEach(function (serviceResponse, i) {
1815
- if (common.getProp(serviceResponse, "serviceItemId")) {
1816
- var id = serviceResponse.serviceItemId;
1817
- if (dependencies.indexOf(id) < 0) {
1818
- dependencies.push(id);
1819
- }
1820
- urlHash[layers[i].url] = id;
1821
- }
1822
- });
1823
- resolve({
1824
- dependencies: dependencies,
1825
- urlHash: urlHash
1826
- });
1827
- }, function (e) { return reject(common.fail(e)); });
1828
- }
1829
- else {
1830
- resolve({
1831
- dependencies: dependencies,
1832
- urlHash: urlHash
1833
- });
1834
- }
1835
- });
1836
- }
1837
- /**
1838
- * Templatizes the url and item id for layers or tables within the webmap.
1839
- *
1840
- * @param layerList List of map layers or tables
1841
- * @param urlHash Lookup object for analysis layers
1842
- * @return void
1843
- * @protected
1844
- */
1845
- function _templatizeWebmapLayerIdsAndUrls(layerList, urlHash) {
1846
- if (layerList === void 0) { layerList = []; }
1847
- layerList.forEach(function (layer) {
1848
- if (layer.url) {
1849
- var layerId = layer.url.substr(layer.url.lastIndexOf("/") + 1);
1850
- var id = Object.keys(urlHash).indexOf(layer.url) > -1
1851
- ? urlHash[layer.url]
1852
- : undefined;
1853
- if (id) {
1854
- layer.url = common.templatizeTerm(id, id, ".layer" + layerId + ".url");
1855
- layer.itemId = common.templatizeTerm(id, id, ".layer" + layerId + ".itemId");
1856
- }
1857
- }
1858
- });
1859
- }
1860
- /**
1861
- * Templatize field references.
1862
- *
1863
- * @param solutionTemplate The solution item template
1864
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
1865
- * @returns The solutionTemplate with templatized field references
1866
- */
1867
- function postProcessFieldReferences$2(solutionTemplate, datasourceInfos) {
1868
- var paths = [
1869
- "data.operationalLayers",
1870
- "data.tables",
1871
- "data.applicationProperties.viewing.search.layers"
1872
- ];
1873
- paths.forEach(function (p) { return _templatizeProperty(solutionTemplate, datasourceInfos, p); });
1874
- return solutionTemplate;
1875
- }
1876
- /**
1877
- * Templatize field references.
1878
- *
1879
- * @param solutionTemplate The solution item template
1880
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
1881
- * @param path A string path to the object property to templatize
1882
- */
1883
- function _templatizeProperty(solutionTemplate, datasourceInfos, path) {
1884
- var objs = common.getProp(solutionTemplate, path);
1885
- if (objs) {
1886
- common.setProp(solutionTemplate, path, _templatize$1(objs, datasourceInfos));
1887
- }
1888
- }
1889
- /**
1890
- * Templatize field references.
1891
- *
1892
- * @param objs Can be operationalLayers or tables or appProperties search layers
1893
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
1894
- * @returns updated instances of the objects
1895
- */
1896
- function _templatize$1(objs, datasourceInfos) {
1897
- objs.forEach(function (obj) {
1898
- var ds = _getDatasourceInfo$1(obj, datasourceInfos);
1899
- if (ds) {
1900
- var fieldNames = ds.fields.map(function (f) { return f.name; });
1901
- common._templatizePopupInfo(obj, ds, ds.basePath, ds.itemId, fieldNames);
1902
- common._templatizeDefinitionEditor(obj, ds.basePath, fieldNames);
1903
- if (obj.layerDefinition) {
1904
- common._templatizeDrawingInfo(obj.layerDefinition, ds.basePath, fieldNames);
1905
- common._templatizeDefinitionExpression(obj.layerDefinition, ds.basePath, fieldNames);
1906
- }
1907
- // used for applicationProperties search layers
1908
- var fieldName = common.getProp(obj, "field.name");
1909
- if (fieldName) {
1910
- common.setProp(obj, "field.name", common._templatizeFieldName(fieldName, obj, ds.itemId, ds.basePath));
1911
- }
1912
- }
1913
- });
1914
- return objs;
1915
- }
1916
- /**
1917
- * Get datasourceInfo by map layer id
1918
- *
1919
- * @param obj Can be operationalLayer or table or appProperties search layer
1920
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
1921
- * @returns datasourceInfo for the given object id
1922
- */
1923
- function _getDatasourceInfo$1(obj, datasourceInfos) {
1924
- var datasourceInfo;
1925
- datasourceInfos.some(function (ds) {
1926
- if (ds.ids.indexOf(obj.id) > -1) {
1927
- datasourceInfo = ds;
1928
- return true;
1929
- }
1930
- else {
1931
- return false;
1932
- }
1933
- });
1934
- return datasourceInfo;
1935
- }
1659
+ var quickcapture = /*#__PURE__*/Object.freeze({
1660
+ __proto__: null,
1661
+ convertItemToTemplate: convertItemToTemplate$3,
1662
+ convertQuickCaptureToTemplate: convertQuickCaptureToTemplate,
1663
+ _templatizeApplication: _templatizeApplication,
1664
+ _templatizeAdminEmail: _templatizeAdminEmail,
1665
+ _updateDependencies: _updateDependencies,
1666
+ _templatizeUrl: _templatizeUrl,
1667
+ _templatizeId: _templatizeId,
1668
+ createItemFromTemplate: createItemFromTemplate$1,
1669
+ postProcess: postProcess$1
1670
+ });
1936
1671
 
1937
- /** @license
1938
- * Copyright 2020 Esri
1939
- *
1940
- * Licensed under the Apache License, Version 2.0 (the "License");
1941
- * you may not use this file except in compliance with the License.
1942
- * You may obtain a copy of the License at
1943
- *
1944
- * http://www.apache.org/licenses/LICENSE-2.0
1945
- *
1946
- * Unless required by applicable law or agreed to in writing, software
1947
- * distributed under the License is distributed on an "AS IS" BASIS,
1948
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1949
- * See the License for the specific language governing permissions and
1950
- * limitations under the License.
1951
- */
1952
- /**
1953
- * Converts an item into a template.
1954
- *
1955
- * @param solutionItemId The solution to contain the template
1956
- * @param itemInfo Info about the item
1957
- * @param authentication Credentials for working with AGO
1958
- * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
1959
- *
1960
- * @return A promise that will resolve when the template has been created
1961
- */
1962
- function convertItemToTemplate$7(solutionItemId, itemInfo, authentication, templateDictionary) {
1963
- return new Promise(function (resolve, reject) {
1964
- // Init template
1965
- var itemTemplate = common.createInitializedItemTemplate(itemInfo);
1966
- // Templatize item info property values
1967
- itemTemplate.item.id = common.templatizeTerm(itemTemplate.item.id, itemTemplate.item.id, ".itemId");
1968
- // Request related items
1969
- var relatedPromise = common.getItemRelatedItemsInSameDirection(itemTemplate.itemId, "forward", authentication);
1970
- // Perform type-specific handling
1971
- var dataPromise = Promise.resolve({});
1972
- switch (itemInfo.type) {
1973
- case "Dashboard":
1974
- case "Feature Collection":
1975
- case "Feature Service":
1976
- case "Hub Initiative":
1977
- case "Hub Page":
1978
- case "Hub Site Application":
1979
- case "Insights Model":
1980
- case "Oriented Imagery Catalog":
1981
- case "Project Package":
1982
- case "Workforce Project":
1983
- case "Web Map":
1984
- case "Web Mapping Application":
1985
- case "Web Scene":
1986
- case "Notebook":
1987
- dataPromise = new Promise(function (resolveJSON) {
1988
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
1989
- common.getItemDataAsJson(itemTemplate.itemId, authentication)
1990
- .then(function (json) { return resolveJSON(json); });
1991
- });
1992
- break;
1993
- case "Form":
1994
- dataPromise = common.getItemDataAsFile(itemTemplate.itemId, itemTemplate.item.name, authentication);
1995
- break;
1996
- case "QuickCapture Project":
1997
- dataPromise = common.getItemResourcesFiles(itemTemplate.itemId, authentication);
1998
- break;
1999
- }
2000
- // Errors are handled as resolved empty values; this means that there's no `reject` clause to handle, hence:
2001
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
2002
- Promise.all([dataPromise, relatedPromise]).then(function (responses) {
2003
- var _a = __read(responses, 2), itemDataResponse = _a[0], relatedItemsResponse = _a[1];
2004
- // need to pre-process for velocity urls before they could be templatized by other processors
2005
- itemTemplate.data = common.updateVelocityReferences(itemDataResponse, itemInfo.type, templateDictionary);
2006
- var relationships = relatedItemsResponse;
2007
- // Save the mappings to related items & add those items to the dependencies, but not WMA Code Attachments
2008
- itemTemplate.dependencies = [];
2009
- itemTemplate.relatedItems = [];
2010
- relationships.forEach(function (relationship) {
2011
- /* istanbul ignore else */
2012
- if (relationship.relationshipType !== "WMA2Code") {
2013
- itemTemplate.relatedItems.push(relationship);
2014
- relationship.relatedItemIds.forEach(function (relatedItemId) {
2015
- if (itemTemplate.dependencies.indexOf(relatedItemId) < 0) {
2016
- itemTemplate.dependencies.push(relatedItemId);
2017
- }
2018
- });
2019
- }
2020
- });
2021
- var wrapupPromise = Promise.resolve(null);
2022
- var templateModifyingPromise = Promise.resolve(itemTemplate);
2023
- switch (itemInfo.type) {
2024
- case "Dashboard":
2025
- convertItemToTemplate(itemTemplate);
2026
- break;
2027
- case "Form":
2028
- // Store the form's data in the solution resources, not in template
2029
- itemTemplate.data = null;
2030
- // Store form data
2031
- if (itemDataResponse) {
2032
- var originalFilename = itemTemplate.item.name || itemDataResponse.name;
2033
- var filename_1 = originalFilename && originalFilename !== "undefined"
2034
- ? originalFilename
2035
- : itemTemplate.itemId + ".zip";
2036
- itemTemplate.item.name = filename_1;
2037
- var storageName_1 = common.convertItemResourceToStorageResource(itemTemplate.itemId + "_info_data", filename_1, common.SolutionTemplateFormatVersion);
2038
- wrapupPromise = new Promise(function (resolveDataStorage, rejectDataStorage) {
2039
- common.addResourceFromBlob(itemDataResponse, solutionItemId, storageName_1.folder, filename_1, authentication)
2040
- .then(function () {
2041
- // Update the template's resources
2042
- itemTemplate.resources.push(storageName_1.folder + "/" + storageName_1.filename);
2043
- resolveDataStorage();
2044
- }, rejectDataStorage);
2045
- });
2046
- }
2047
- break;
2048
- case "Notebook":
2049
- convertNotebookToTemplate(itemTemplate);
2050
- break;
2051
- case "Oriented Imagery Catalog":
2052
- templateModifyingPromise = convertItemToTemplate$4(itemTemplate, authentication);
2053
- break;
2054
- case "Web Map":
2055
- case "Web Scene":
2056
- templateModifyingPromise = convertItemToTemplate$6(itemTemplate, authentication);
2057
- break;
2058
- case "Web Mapping Application":
2059
- if (itemDataResponse) {
2060
- templateModifyingPromise = convertItemToTemplate$1(itemTemplate, authentication);
2061
- }
2062
- break;
2063
- case "Workforce Project":
2064
- templateModifyingPromise = convertItemToTemplate$2(itemTemplate, authentication);
2065
- break;
2066
- case "QuickCapture Project":
2067
- templateModifyingPromise = convertQuickCaptureToTemplate(itemTemplate);
2068
- break;
2069
- }
2070
- wrapupPromise.then(function () {
2071
- templateModifyingPromise.then(resolve, function (err) {
2072
- return reject(common.fail(err));
2073
- });
2074
- }, function (err) { return reject(common.fail(err)); });
2075
- });
2076
- });
2077
- }
1672
+ /** @license
1673
+ * Copyright 2018 Esri
1674
+ *
1675
+ * Licensed under the Apache License, Version 2.0 (the "License");
1676
+ * you may not use this file except in compliance with the License.
1677
+ * You may obtain a copy of the License at
1678
+ *
1679
+ * http://www.apache.org/licenses/LICENSE-2.0
1680
+ *
1681
+ * Unless required by applicable law or agreed to in writing, software
1682
+ * distributed under the License is distributed on an "AS IS" BASIS,
1683
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1684
+ * See the License for the specific language governing permissions and
1685
+ * limitations under the License.
1686
+ */
1687
+ /**
1688
+ * The portion of a Webmap URL between the server and the map id.
1689
+ *
1690
+ * @protected
1691
+ */
1692
+ const WEBMAP_APP_URL_PART = "home/webmap/viewer.html?webmap=";
1693
+ // ------------------------------------------------------------------------------------------------------------------ //
1694
+ /**
1695
+ * Converts an AGOL webmap item to a template.
1696
+ *
1697
+ * @param itemTemplate Template for the webmap item
1698
+ * @param destAuthentication Credentials for requests to the destination organization
1699
+ * @param srcAuthentication Credentials for requests to source items
1700
+ * @return Template for the solution item that contains key details for item reconstruction
1701
+ */
1702
+ function convertItemToTemplate$2(itemTemplate, destAuthentication, srcAuthentication) {
1703
+ return new Promise((resolve, reject) => {
1704
+ // Templatize the app URL
1705
+ itemTemplate.item.url =
1706
+ common__namespace.checkUrlPathTermination(common__namespace.placeholder(common__namespace.SERVER_NAME)) +
1707
+ WEBMAP_APP_URL_PART +
1708
+ itemTemplate.item.id; // templatized id
1709
+ // Extract dependencies
1710
+ _extractDependencies(itemTemplate, srcAuthentication).then((results) => {
1711
+ itemTemplate.dependencies = results.dependencies;
1712
+ // Templatize the map layer ids after we've extracted them as dependencies
1713
+ if (itemTemplate.data) {
1714
+ _templatizeWebmapLayerIdsAndUrls(itemTemplate.data.operationalLayers, results.urlHash);
1715
+ _templatizeWebmapLayerIdsAndUrls(itemTemplate.data.tables, results.urlHash);
1716
+ // Exclude intialState
1717
+ _excludeInitialState(itemTemplate.data);
1718
+ }
1719
+ resolve(itemTemplate);
1720
+ }, e => reject(common__namespace.fail(e)));
1721
+ });
1722
+ }
1723
+ /**
1724
+ * Gets the ids of the dependencies of an AGOL webmap item.
1725
+ *
1726
+ * @param itemTemplate A webmap item whose dependencies are sought
1727
+ * @param authentication Credentials for any requests
1728
+ * @return List of dependencies ids and url/itemId hash
1729
+ * @protected
1730
+ */
1731
+ function _extractDependencies(itemTemplate, authentication) {
1732
+ return new Promise((resolve, reject) => {
1733
+ const dependencies = [];
1734
+ if (itemTemplate.data) {
1735
+ const layers = itemTemplate.data.operationalLayers || [];
1736
+ const tables = itemTemplate.data.tables || [];
1737
+ const layersAndTables = layers.concat(tables);
1738
+ _getLayerIds(layersAndTables, dependencies, authentication).then(results => {
1739
+ resolve(results);
1740
+ }, e => reject(common__namespace.fail(e)));
1741
+ }
1742
+ else {
1743
+ resolve({
1744
+ dependencies: dependencies,
1745
+ urlHash: {}
1746
+ });
1747
+ }
1748
+ });
1749
+ }
1750
+ /**
1751
+ * Remove the initialState prop from webmaps saved from the new map viewer.
1752
+ * This allows the map to use the item extent property that we templatize.
1753
+ *
1754
+ * Added for issue #662
1755
+ *
1756
+ * @param data the data for the web maps item template
1757
+ * @return void
1758
+ * @protected
1759
+ */
1760
+ function _excludeInitialState(data) {
1761
+ common__namespace.deleteProp(data, "initialState");
1762
+ }
1763
+ /**
1764
+ * Extracts the AGOL itemId for each layer or table object in a list using the url.
1765
+ *
1766
+ * @param layerList List of map layers or tables
1767
+ * @param dependencies Current list of dependencies
1768
+ * @param authentication Credentials for any requests
1769
+ * @return List of dependencies ids and url/itemId hash
1770
+ * @protected
1771
+ */
1772
+ function _getLayerIds(layerList, dependencies, authentication) {
1773
+ return new Promise((resolve, reject) => {
1774
+ const urlHash = {};
1775
+ const options = {
1776
+ f: "json",
1777
+ authentication: authentication
1778
+ };
1779
+ const layerPromises = [];
1780
+ const layerChecks = {};
1781
+ const layers = layerList.filter(layer => {
1782
+ if (layer.url && layer.url.indexOf("{{velocityUrl}}") < 0) {
1783
+ const results = /.+FeatureServer/g.exec(layer.url);
1784
+ const baseUrl = Array.isArray(results) && results.length > 0 ? results[0] : undefined;
1785
+ if (baseUrl) {
1786
+ // avoid redundant checks when we have a layer with subLayers
1787
+ if (Object.keys(layerChecks).indexOf(baseUrl) < 0) {
1788
+ layerChecks[baseUrl] = common__namespace.rest_request(layer.url, options);
1789
+ }
1790
+ layerPromises.push(layerChecks[baseUrl]);
1791
+ return true;
1792
+ }
1793
+ else {
1794
+ return false;
1795
+ }
1796
+ }
1797
+ else {
1798
+ return false;
1799
+ }
1800
+ });
1801
+ if (layerPromises.length > 0) {
1802
+ Promise.all(layerPromises).then(serviceResponses => {
1803
+ serviceResponses.forEach((serviceResponse, i) => {
1804
+ if (common__namespace.getProp(serviceResponse, "serviceItemId")) {
1805
+ const id = serviceResponse.serviceItemId;
1806
+ if (dependencies.indexOf(id) < 0) {
1807
+ dependencies.push(id);
1808
+ }
1809
+ urlHash[layers[i].url] = id;
1810
+ }
1811
+ });
1812
+ resolve({
1813
+ dependencies: dependencies,
1814
+ urlHash: urlHash
1815
+ });
1816
+ }, e => reject(common__namespace.fail(e)));
1817
+ }
1818
+ else {
1819
+ resolve({
1820
+ dependencies: dependencies,
1821
+ urlHash: urlHash
1822
+ });
1823
+ }
1824
+ });
1825
+ }
1826
+ /**
1827
+ * Templatizes the url and item id for layers or tables within the webmap.
1828
+ *
1829
+ * @param layerList List of map layers or tables
1830
+ * @param urlHash Lookup object for analysis layers
1831
+ * @return void
1832
+ * @protected
1833
+ */
1834
+ function _templatizeWebmapLayerIdsAndUrls(layerList = [], urlHash) {
1835
+ layerList.forEach((layer) => {
1836
+ if (layer.url) {
1837
+ const layerId = layer.url.substr(layer.url.lastIndexOf("/") + 1);
1838
+ const id = Object.keys(urlHash).indexOf(layer.url) > -1
1839
+ ? urlHash[layer.url]
1840
+ : undefined;
1841
+ if (id) {
1842
+ layer.url = common__namespace.templatizeTerm(id, id, ".layer" + layerId + ".url");
1843
+ layer.itemId = common__namespace.templatizeTerm(id, id, ".layer" + layerId + ".itemId");
1844
+ }
1845
+ }
1846
+ });
1847
+ }
1848
+ /**
1849
+ * Templatize field references.
1850
+ *
1851
+ * @param solutionTemplate The solution item template
1852
+ * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
1853
+ * @returns The solutionTemplate with templatized field references
1854
+ */
1855
+ function postProcessFieldReferences$1(solutionTemplate, datasourceInfos) {
1856
+ const paths = [
1857
+ "data.operationalLayers",
1858
+ "data.tables",
1859
+ "data.applicationProperties.viewing.search.layers"
1860
+ ];
1861
+ paths.forEach(p => _templatizeProperty(solutionTemplate, datasourceInfos, p));
1862
+ return solutionTemplate;
1863
+ }
1864
+ /**
1865
+ * Templatize field references.
1866
+ *
1867
+ * @param solutionTemplate The solution item template
1868
+ * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
1869
+ * @param path A string path to the object property to templatize
1870
+ */
1871
+ function _templatizeProperty(solutionTemplate, datasourceInfos, path) {
1872
+ const objs = common__namespace.getProp(solutionTemplate, path);
1873
+ if (objs) {
1874
+ common__namespace.setProp(solutionTemplate, path, _templatize(objs, datasourceInfos));
1875
+ }
1876
+ }
1877
+ /**
1878
+ * Templatize field references.
1879
+ *
1880
+ * @param objs Can be operationalLayers or tables or appProperties search layers
1881
+ * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
1882
+ * @returns updated instances of the objects
1883
+ */
1884
+ function _templatize(objs, datasourceInfos) {
1885
+ objs.forEach(obj => {
1886
+ const ds = _getDatasourceInfo(obj, datasourceInfos);
1887
+ if (ds) {
1888
+ const fieldNames = ds.fields.map(f => f.name);
1889
+ common__namespace._templatizePopupInfo(obj, ds, ds.basePath, ds.itemId, fieldNames);
1890
+ common__namespace._templatizeDefinitionEditor(obj, ds.basePath, fieldNames);
1891
+ if (obj.layerDefinition) {
1892
+ common__namespace._templatizeDrawingInfo(obj.layerDefinition, ds.basePath, fieldNames);
1893
+ common__namespace._templatizeDefinitionExpression(obj.layerDefinition, ds.basePath, fieldNames);
1894
+ }
1895
+ // used for applicationProperties search layers
1896
+ const fieldName = common__namespace.getProp(obj, "field.name");
1897
+ if (fieldName) {
1898
+ common__namespace.setProp(obj, "field.name", common__namespace._templatizeFieldName(fieldName, obj, ds.itemId, ds.basePath));
1899
+ }
1900
+ }
1901
+ });
1902
+ return objs;
1903
+ }
1904
+ /**
1905
+ * Get datasourceInfo by map layer id
1906
+ *
1907
+ * @param obj Can be operationalLayer or table or appProperties search layer
1908
+ * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
1909
+ * @returns datasourceInfo for the given object id
1910
+ */
1911
+ function _getDatasourceInfo(obj, datasourceInfos) {
1912
+ let datasourceInfo;
1913
+ datasourceInfos.some(ds => {
1914
+ if (ds.ids.indexOf(obj.id) > -1) {
1915
+ datasourceInfo = ds;
1916
+ return true;
1917
+ }
1918
+ else {
1919
+ return false;
1920
+ }
1921
+ });
1922
+ return datasourceInfo;
1923
+ }
2078
1924
 
2079
- /** @license
2080
- * Copyright 2020 Esri
2081
- *
2082
- * Licensed under the Apache License, Version 2.0 (the "License");
2083
- * you may not use this file except in compliance with the License.
2084
- * You may obtain a copy of the License at
2085
- *
2086
- * http://www.apache.org/licenses/LICENSE-2.0
2087
- *
2088
- * Unless required by applicable law or agreed to in writing, software
2089
- * distributed under the License is distributed on an "AS IS" BASIS,
2090
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2091
- * See the License for the specific language governing permissions and
2092
- * limitations under the License.
2093
- */
1925
+ /** @license
1926
+ * Copyright 2020 Esri
1927
+ *
1928
+ * Licensed under the Apache License, Version 2.0 (the "License");
1929
+ * you may not use this file except in compliance with the License.
1930
+ * You may obtain a copy of the License at
1931
+ *
1932
+ * http://www.apache.org/licenses/LICENSE-2.0
1933
+ *
1934
+ * Unless required by applicable law or agreed to in writing, software
1935
+ * distributed under the License is distributed on an "AS IS" BASIS,
1936
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1937
+ * See the License for the specific language governing permissions and
1938
+ * limitations under the License.
1939
+ */
1940
+ /**
1941
+ * Converts an item into a template.
1942
+ *
1943
+ * @param solutionItemId The solution to contain the template
1944
+ * @param itemInfo Info about the item
1945
+ * @param destAuthentication Credentials for requests to the destination organization
1946
+ * @param srcAuthentication Credentials for requests to source items
1947
+ * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
1948
+ *
1949
+ * @return A promise that will resolve when the template has been created
1950
+ */
1951
+ function convertItemToTemplate$1(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary) {
1952
+ return new Promise((resolve, reject) => {
1953
+ // Init template
1954
+ const itemTemplate = common__namespace.createInitializedItemTemplate(itemInfo);
1955
+ // Templatize item info property values
1956
+ itemTemplate.item.id = common__namespace.templatizeTerm(itemTemplate.item.id, itemTemplate.item.id, ".itemId");
1957
+ // Request related items
1958
+ const relatedPromise = common__namespace.getItemRelatedItemsInSameDirection(itemTemplate.itemId, "forward", srcAuthentication);
1959
+ // Perform type-specific handling
1960
+ let dataPromise = Promise.resolve({});
1961
+ switch (itemInfo.type) {
1962
+ case "Dashboard":
1963
+ case "Feature Collection":
1964
+ case "Feature Service":
1965
+ case "Hub Initiative":
1966
+ case "Hub Page":
1967
+ case "Hub Site Application":
1968
+ case "Insights Model":
1969
+ case "Oriented Imagery Catalog":
1970
+ case "Project Package":
1971
+ case "Workforce Project":
1972
+ case "Web Map":
1973
+ case "Web Mapping Application":
1974
+ case "Web Scene":
1975
+ case "Notebook":
1976
+ dataPromise = new Promise(resolveJSON => {
1977
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
1978
+ common__namespace
1979
+ .getItemDataAsJson(itemTemplate.itemId, srcAuthentication)
1980
+ .then(json => resolveJSON(json));
1981
+ });
1982
+ break;
1983
+ case "Form":
1984
+ dataPromise = common__namespace.getItemDataAsFile(itemTemplate.itemId, itemTemplate.item.name, srcAuthentication);
1985
+ break;
1986
+ case "QuickCapture Project":
1987
+ dataPromise = common__namespace.getItemResourcesFiles(itemTemplate.itemId, srcAuthentication);
1988
+ break;
1989
+ }
1990
+ // Errors are handled as resolved empty values; this means that there's no `reject` clause to handle, hence:
1991
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
1992
+ Promise.all([dataPromise, relatedPromise]).then(responses => {
1993
+ const [itemDataResponse, relatedItemsResponse] = responses;
1994
+ // need to pre-process for velocity urls before they could be templatized by other processors
1995
+ itemTemplate.data = common__namespace.updateVelocityReferences(itemDataResponse, itemInfo.type, templateDictionary);
1996
+ const relationships = relatedItemsResponse;
1997
+ // Save the mappings to related items & add those items to the dependencies, but not WMA Code Attachments
1998
+ itemTemplate.dependencies = [];
1999
+ itemTemplate.relatedItems = [];
2000
+ relationships.forEach(relationship => {
2001
+ /* istanbul ignore else */
2002
+ if (relationship.relationshipType !== "WMA2Code") {
2003
+ itemTemplate.relatedItems.push(relationship);
2004
+ relationship.relatedItemIds.forEach(relatedItemId => {
2005
+ if (itemTemplate.dependencies.indexOf(relatedItemId) < 0) {
2006
+ itemTemplate.dependencies.push(relatedItemId);
2007
+ }
2008
+ });
2009
+ }
2010
+ });
2011
+ let wrapupPromise = Promise.resolve(null);
2012
+ let templateModifyingPromise = Promise.resolve(itemTemplate);
2013
+ switch (itemInfo.type) {
2014
+ case "Dashboard":
2015
+ convertItemToTemplate$8(itemTemplate);
2016
+ break;
2017
+ case "Form":
2018
+ // Store the form's data in the solution resources, not in template
2019
+ itemTemplate.data = null;
2020
+ // Store form data
2021
+ if (itemDataResponse) {
2022
+ const originalFilename = itemTemplate.item.name || itemDataResponse.name;
2023
+ const filename = originalFilename && originalFilename !== "undefined"
2024
+ ? originalFilename
2025
+ : `${itemTemplate.itemId}.zip`;
2026
+ itemTemplate.item.name = filename;
2027
+ const storageName = common__namespace.convertItemResourceToStorageResource(itemTemplate.itemId + "_info_data", filename, common__namespace.SolutionTemplateFormatVersion);
2028
+ wrapupPromise = new Promise((resolveDataStorage, rejectDataStorage) => {
2029
+ common__namespace
2030
+ .addResourceFromBlob(itemDataResponse, solutionItemId, storageName.folder, filename, destAuthentication)
2031
+ .then(() => {
2032
+ // Update the template's resources
2033
+ itemTemplate.resources.push(storageName.folder + "/" + storageName.filename);
2034
+ resolveDataStorage();
2035
+ }, rejectDataStorage);
2036
+ });
2037
+ }
2038
+ break;
2039
+ case "Notebook":
2040
+ convertNotebookToTemplate(itemTemplate);
2041
+ break;
2042
+ case "Oriented Imagery Catalog":
2043
+ templateModifyingPromise = convertItemToTemplate$4(itemTemplate, destAuthentication, srcAuthentication);
2044
+ break;
2045
+ case "Web Map":
2046
+ case "Web Scene":
2047
+ templateModifyingPromise = convertItemToTemplate$2(itemTemplate, destAuthentication, srcAuthentication);
2048
+ break;
2049
+ case "Web Mapping Application":
2050
+ if (itemDataResponse) {
2051
+ templateModifyingPromise = convertItemToTemplate$7(itemTemplate, destAuthentication, srcAuthentication);
2052
+ }
2053
+ break;
2054
+ case "Workforce Project":
2055
+ templateModifyingPromise = convertItemToTemplate$6(itemTemplate, destAuthentication, srcAuthentication);
2056
+ break;
2057
+ case "QuickCapture Project":
2058
+ templateModifyingPromise = convertQuickCaptureToTemplate(itemTemplate);
2059
+ break;
2060
+ }
2061
+ wrapupPromise.then(() => {
2062
+ templateModifyingPromise.then(resolve, err => reject(common__namespace.fail(err)));
2063
+ }, err => reject(common__namespace.fail(err)));
2064
+ });
2065
+ });
2066
+ }
2094
2067
 
2095
- var simpleTypeHelpers = /*#__PURE__*/Object.freeze({
2096
- __proto__: null,
2097
- createItemFromTemplate: createItemFromTemplate,
2098
- convertItemToTemplate: convertItemToTemplate$7
2099
- });
2068
+ /** @license
2069
+ * Copyright 2020 Esri
2070
+ *
2071
+ * Licensed under the Apache License, Version 2.0 (the "License");
2072
+ * you may not use this file except in compliance with the License.
2073
+ * You may obtain a copy of the License at
2074
+ *
2075
+ * http://www.apache.org/licenses/LICENSE-2.0
2076
+ *
2077
+ * Unless required by applicable law or agreed to in writing, software
2078
+ * distributed under the License is distributed on an "AS IS" BASIS,
2079
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2080
+ * See the License for the specific language governing permissions and
2081
+ * limitations under the License.
2082
+ */
2100
2083
 
2101
- /** @license
2102
- * Copyright 2018 Esri
2103
- *
2104
- * Licensed under the Apache License, Version 2.0 (the "License");
2105
- * you may not use this file except in compliance with the License.
2106
- * You may obtain a copy of the License at
2107
- *
2108
- * http://www.apache.org/licenses/LICENSE-2.0
2109
- *
2110
- * Unless required by applicable law or agreed to in writing, software
2111
- * distributed under the License is distributed on an "AS IS" BASIS,
2112
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2113
- * See the License for the specific language governing permissions and
2114
- * limitations under the License.
2115
- */
2116
- /**
2117
- * Converts an item into a template.
2118
- *
2119
- * @param solutionItemId The solution to contain the template
2120
- * @param itemInfo Info about the item
2121
- * @param authentication Credentials for working with AGO
2122
- * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
2123
- * @return A promise that will resolve when the template has been created
2124
- */
2125
- function convertItemToTemplate$8(solutionItemId, itemInfo, authentication, templateDictionary) {
2126
- return convertItemToTemplate$7(solutionItemId, itemInfo, authentication, templateDictionary);
2127
- }
2128
- /**
2129
- * Delegate to simpleType creator
2130
- *
2131
- * @param template
2132
- * @param templateDictionary
2133
- * @param destinationAuthentication
2134
- * @param itemProgressCallback
2135
- */
2136
- function createItemFromTemplate$3(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
2137
- return createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback);
2138
- }
2139
- /**
2140
- * Templatizes field references within specific template types.
2141
- * Currently only handles web mapping applications
2142
- *
2143
- * @param template A solution template
2144
- * @param datasourceInfos A list of objects that store key datasource info used to templatizing field references
2145
- * @param type The item type
2146
- * @return The updated solution template
2147
- */
2148
- function postProcessFieldReferences$3(solutionTemplate, datasourceInfos, type) {
2149
- switch (type) {
2150
- case "Web Mapping Application":
2151
- postProcessFieldReferences$1(solutionTemplate, datasourceInfos);
2152
- break;
2153
- case "Dashboard":
2154
- postProcessFieldReferences(solutionTemplate, datasourceInfos);
2155
- break;
2156
- case "Web Map":
2157
- postProcessFieldReferences$2(solutionTemplate, datasourceInfos);
2158
- break;
2159
- }
2160
- return solutionTemplate;
2161
- }
2162
- /**
2163
- * Simple Type post-processing actions
2164
- *
2165
- * @param {string} itemId The item ID
2166
- * @param {string} type The template type
2167
- * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects
2168
- * @param {any} templateDictionary The template dictionary
2169
- * @param {UserSession} authentication The destination session info
2170
- * @returns Promise resolving to successfulness of update
2171
- */
2172
- function postProcess$2(itemId, type, itemInfos, template, templates, templateDictionary, authentication) {
2173
- return common.updateItemTemplateFromDictionary(itemId, templateDictionary, authentication);
2174
- }
2084
+ var simpleTypeHelpers = /*#__PURE__*/Object.freeze({
2085
+ __proto__: null,
2086
+ createItemFromTemplate: createItemFromTemplate$3,
2087
+ convertItemToTemplate: convertItemToTemplate$1
2088
+ });
2089
+
2090
+ /** @license
2091
+ * Copyright 2018 Esri
2092
+ *
2093
+ * Licensed under the Apache License, Version 2.0 (the "License");
2094
+ * you may not use this file except in compliance with the License.
2095
+ * You may obtain a copy of the License at
2096
+ *
2097
+ * http://www.apache.org/licenses/LICENSE-2.0
2098
+ *
2099
+ * Unless required by applicable law or agreed to in writing, software
2100
+ * distributed under the License is distributed on an "AS IS" BASIS,
2101
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2102
+ * See the License for the specific language governing permissions and
2103
+ * limitations under the License.
2104
+ */
2105
+ /**
2106
+ * Converts an item into a template.
2107
+ *
2108
+ * @param solutionItemId The solution to contain the template
2109
+ * @param itemInfo Info about the item
2110
+ * @param destAuthentication Credentials for requests to the destination organization
2111
+ * @param srcAuthentication Credentials for requests to source items
2112
+ * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
2113
+ * @return A promise that will resolve when the template has been created
2114
+ */
2115
+ function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary) {
2116
+ return convertItemToTemplate$1(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary);
2117
+ }
2118
+ /**
2119
+ * Delegate to simpleType creator
2120
+ *
2121
+ * @param template
2122
+ * @param templateDictionary
2123
+ * @param destinationAuthentication
2124
+ * @param itemProgressCallback
2125
+ */
2126
+ function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
2127
+ return createItemFromTemplate$3(template, templateDictionary, destinationAuthentication, itemProgressCallback);
2128
+ }
2129
+ /**
2130
+ * Templatizes field references within specific template types.
2131
+ * Currently only handles web mapping applications
2132
+ *
2133
+ * @param template A solution template
2134
+ * @param datasourceInfos A list of objects that store key datasource info used to templatizing field references
2135
+ * @param type The item type
2136
+ * @return The updated solution template
2137
+ */
2138
+ function postProcessFieldReferences(solutionTemplate, datasourceInfos, type) {
2139
+ switch (type) {
2140
+ case "Web Mapping Application":
2141
+ postProcessFieldReferences$2(solutionTemplate, datasourceInfos);
2142
+ break;
2143
+ case "Dashboard":
2144
+ postProcessFieldReferences$3(solutionTemplate, datasourceInfos);
2145
+ break;
2146
+ case "Web Map":
2147
+ postProcessFieldReferences$1(solutionTemplate, datasourceInfos);
2148
+ break;
2149
+ }
2150
+ return solutionTemplate;
2151
+ }
2152
+ /**
2153
+ * Simple Type post-processing actions
2154
+ *
2155
+ * @param {string} itemId The item ID
2156
+ * @param {string} type The template type
2157
+ * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects
2158
+ * @param {any} templateDictionary The template dictionary
2159
+ * @param {UserSession} authentication The destination session info
2160
+ * @returns Promise resolving to successfulness of update
2161
+ */
2162
+ function postProcess(itemId, type, itemInfos, template, templates, templateDictionary, authentication) {
2163
+ return common.updateItemTemplateFromDictionary(itemId, templateDictionary, authentication);
2164
+ }
2175
2165
 
2176
- var simpleTypes = /*#__PURE__*/Object.freeze({
2177
- __proto__: null,
2178
- convertItemToTemplate: convertItemToTemplate$8,
2179
- createItemFromTemplate: createItemFromTemplate$3,
2180
- postProcessFieldReferences: postProcessFieldReferences$3,
2181
- postProcess: postProcess$2
2182
- });
2166
+ var simpleTypes = /*#__PURE__*/Object.freeze({
2167
+ __proto__: null,
2168
+ convertItemToTemplate: convertItemToTemplate,
2169
+ createItemFromTemplate: createItemFromTemplate,
2170
+ postProcessFieldReferences: postProcessFieldReferences,
2171
+ postProcess: postProcess
2172
+ });
2183
2173
 
2184
- exports.notebookHelpers = notebookHelpers;
2185
- exports.notebookProcessor = notebook;
2186
- exports.quickcaptureHelpers = quickcaptureHelpers;
2187
- exports.quickcaptureProcessor = quickcapture;
2188
- exports.simpleTypeHelpers = simpleTypeHelpers;
2189
- exports.simpleTypes = simpleTypes;
2174
+ exports.notebookHelpers = notebookHelpers;
2175
+ exports.notebookProcessor = notebook;
2176
+ exports.quickcaptureHelpers = quickcaptureHelpers;
2177
+ exports.quickcaptureProcessor = quickcapture;
2178
+ exports.simpleTypeHelpers = simpleTypeHelpers;
2179
+ exports.simpleTypes = simpleTypes;
2190
2180
 
2191
- Object.defineProperty(exports, '__esModule', { value: true });
2181
+ Object.defineProperty(exports, '__esModule', { value: true });
2192
2182
 
2193
- })));
2183
+ }));
2194
2184
  //# sourceMappingURL=simple-types.umd.js.map