@esri/solution-creator 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/esm/createItemTemplate.d.ts +12 -1
  2. package/dist/esm/createItemTemplate.js +42 -3
  3. package/dist/esm/createItemTemplate.js.map +1 -1
  4. package/dist/esm/helpers/add-content-to-solution.js +5 -1
  5. package/dist/esm/helpers/add-content-to-solution.js.map +1 -1
  6. package/package.json +13 -13
  7. package/dist/node/createItemTemplate.d.ts +0 -97
  8. package/dist/node/createItemTemplate.js +0 -376
  9. package/dist/node/createItemTemplate.js.map +0 -1
  10. package/dist/node/creator.d.ts +0 -97
  11. package/dist/node/creator.js +0 -279
  12. package/dist/node/creator.js.map +0 -1
  13. package/dist/node/helpers/add-content-to-solution.d.ts +0 -126
  14. package/dist/node/helpers/add-content-to-solution.js +0 -461
  15. package/dist/node/helpers/add-content-to-solution.js.map +0 -1
  16. package/dist/node/helpers/template.d.ts +0 -30
  17. package/dist/node/helpers/template.js +0 -49
  18. package/dist/node/helpers/template.js.map +0 -1
  19. package/dist/node/index.d.ts +0 -23
  20. package/dist/node/index.js +0 -27
  21. package/dist/node/index.js.map +0 -1
  22. package/dist/node/module-map.d.ts +0 -23
  23. package/dist/node/module-map.js +0 -195
  24. package/dist/node/module-map.js.map +0 -1
  25. package/dist/umd/creator/src/createItemTemplate.d.ts +0 -97
  26. package/dist/umd/creator/src/creator.d.ts +0 -97
  27. package/dist/umd/creator/src/helpers/add-content-to-solution.d.ts +0 -126
  28. package/dist/umd/creator/src/helpers/template.d.ts +0 -30
  29. package/dist/umd/creator/src/index.d.ts +0 -23
  30. package/dist/umd/creator/src/module-map.d.ts +0 -23
  31. package/dist/umd/creator.umd.js +0 -1353
  32. package/dist/umd/creator.umd.js.map +0 -1
  33. package/dist/umd/creator.umd.min.js +0 -19
  34. package/dist/umd/creator.umd.min.js.map +0 -1
@@ -1,1353 +0,0 @@
1
- /* @preserve
2
- * @esri/solution-creator - v1.7.0 - Apache-2.0
3
- * Copyright (c) 2018-2023 Esri, Inc.
4
- * Fri Apr 28 2023 11:23:40 GMT-0700 (Pacific Daylight Time)
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
- (function (global, factory) {
19
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/solution-common'), require('@esri/hub-common'), require('@esri/solution-feature-layer'), require('@esri/solution-file'), require('@esri/solution-form'), require('@esri/solution-group'), require('@esri/solution-simple-types'), require('@esri/solution-storymap'), require('@esri/solution-velocity'), require('@esri/solution-web-experience'), require('@esri/solution-hub-types')) :
20
- typeof define === 'function' && define.amd ? define(['exports', '@esri/solution-common', '@esri/hub-common', '@esri/solution-feature-layer', '@esri/solution-file', '@esri/solution-form', '@esri/solution-group', '@esri/solution-simple-types', '@esri/solution-storymap', '@esri/solution-velocity', '@esri/solution-web-experience', '@esri/solution-hub-types'], factory) :
21
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution, global.arcgisHub, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution, global.arcgisSolution));
22
- })(this, (function (exports, solutionCommon, hubCommon, featureLayer, fileProcessor, formProcessor, group, solutionSimpleTypes, solutionStorymap, solutionVelocity, solutionWebExperience, solutionHubTypes) { 'use strict';
23
-
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
- });
37
- }
38
- n["default"] = e;
39
- return Object.freeze(n);
40
- }
41
-
42
- var featureLayer__namespace = /*#__PURE__*/_interopNamespace(featureLayer);
43
- var fileProcessor__namespace = /*#__PURE__*/_interopNamespace(fileProcessor);
44
- var formProcessor__namespace = /*#__PURE__*/_interopNamespace(formProcessor);
45
- var group__namespace = /*#__PURE__*/_interopNamespace(group);
46
-
47
- /** @license
48
- * Copyright 2020 Esri
49
- *
50
- * Licensed under the Apache License, Version 2.0 (the "License");
51
- * you may not use this file except in compliance with the License.
52
- * You may obtain a copy of the License at
53
- *
54
- * http://www.apache.org/licenses/LICENSE-2.0
55
- *
56
- * Unless required by applicable law or agreed to in writing, software
57
- * distributed under the License is distributed on an "AS IS" BASIS,
58
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59
- * See the License for the specific language governing permissions and
60
- * limitations under the License.
61
- */
62
- const UNSUPPORTED = null;
63
- /**
64
- * Mapping from item type to module with type-specific template-handling code.
65
- * AGO types come from a blend of arcgis-portal-app\src\js\arcgisonline\pages\item\_Info.js and
66
- * arcgis-portal-app\src\js\arcgis-components\src\_utils\metadata\item\displayName.ts
67
- */
68
- const moduleMap = {
69
- ////////////////////////////////////////////////////////
70
- // Group type
71
- Group: group__namespace,
72
- ////////////////////////////////////////////////////////
73
- // Layer types
74
- "Big Data Analytic": solutionVelocity.VelocityProcessor,
75
- "Feature Collection": solutionSimpleTypes.simpleTypes,
76
- "Feature Service": featureLayer__namespace,
77
- Feed: solutionVelocity.VelocityProcessor,
78
- "Geocoding Service": undefined,
79
- "Geodata Service": undefined,
80
- "Geometry Service": undefined,
81
- "Geoprocessing Service": undefined,
82
- "Globe Service": undefined,
83
- "Image Service": undefined,
84
- KML: undefined,
85
- "Map Service": featureLayer__namespace,
86
- "Network Analysis Service": undefined,
87
- "Real Time Analytic": solutionVelocity.VelocityProcessor,
88
- "Relational Database Connection": undefined,
89
- "Scene Service": undefined,
90
- "Stream Service": undefined,
91
- Tool: undefined,
92
- "Vector Tile Service": undefined,
93
- WFS: undefined,
94
- WMS: undefined,
95
- WMTS: undefined,
96
- "Workflow Manager Service": undefined,
97
- ////////////////////////////////////////////////////////
98
- // Map types
99
- "3D Web Scene": undefined,
100
- "Web Map": solutionSimpleTypes.simpleTypes,
101
- "Web Scene": solutionSimpleTypes.simpleTypes,
102
- ////////////////////////////////////////////////////////
103
- // App types
104
- Application: undefined,
105
- Dashboard: solutionSimpleTypes.simpleTypes,
106
- "Data Store": undefined,
107
- "Desktop Application": undefined,
108
- "Excalibur Imagery Project": undefined,
109
- Form: formProcessor__namespace,
110
- "Hub Initiative": UNSUPPORTED,
111
- "Hub Page": solutionHubTypes.HubPageProcessor,
112
- "Hub Site Application": solutionHubTypes.HubSiteProcessor,
113
- "Insights Model": solutionSimpleTypes.simpleTypes,
114
- "Insights Page": undefined,
115
- "Insights Theme": undefined,
116
- "Insights Workbook": undefined,
117
- Mission: undefined,
118
- "Mobile Application": undefined,
119
- Notebook: solutionSimpleTypes.notebookProcessor,
120
- "Oriented Imagery Catalog": solutionSimpleTypes.simpleTypes,
121
- "Ortho Mapping Project": undefined,
122
- "QuickCapture Project": solutionSimpleTypes.quickcaptureProcessor,
123
- "Site Application": solutionHubTypes.HubSiteProcessor,
124
- "Site Page": solutionHubTypes.HubPageProcessor,
125
- Solution: UNSUPPORTED,
126
- StoryMap: solutionStorymap.StoryMapProcessor,
127
- "Urban Model": undefined,
128
- "Web Experience Template": undefined,
129
- "Web Experience": solutionWebExperience.WebExperienceProcessor,
130
- "Web Mapping Application": solutionSimpleTypes.simpleTypes,
131
- "Workforce Project": solutionSimpleTypes.simpleTypes,
132
- ////////////////////////////////////////////////////////
133
- // File types
134
- "360 VR Experience": fileProcessor__namespace,
135
- "AppBuilder Extension": fileProcessor__namespace,
136
- "AppBuilder Widget Package": fileProcessor__namespace,
137
- "Application Configuration": fileProcessor__namespace,
138
- "ArcGIS Pro Add In": fileProcessor__namespace,
139
- "ArcGIS Pro Configuration": fileProcessor__namespace,
140
- "ArcPad Package": fileProcessor__namespace,
141
- "Basemap Package": fileProcessor__namespace,
142
- "CAD Drawing": fileProcessor__namespace,
143
- "CityEngine Web Scene": fileProcessor__namespace,
144
- "Code Attachment": UNSUPPORTED,
145
- "Code Sample": fileProcessor__namespace,
146
- "Color Set": fileProcessor__namespace,
147
- "Compact Tile Package": fileProcessor__namespace,
148
- "CSV Collection": fileProcessor__namespace,
149
- CSV: fileProcessor__namespace,
150
- "Deep Learning Package": fileProcessor__namespace,
151
- "Desktop Add In": fileProcessor__namespace,
152
- "Desktop Application Template": fileProcessor__namespace,
153
- "Desktop Style": fileProcessor__namespace,
154
- "Document Link": fileProcessor__namespace,
155
- "Explorer Add In": fileProcessor__namespace,
156
- "Explorer Layer": fileProcessor__namespace,
157
- "Explorer Map": fileProcessor__namespace,
158
- "Feature Collection Template": fileProcessor__namespace,
159
- "File Geodatabase": fileProcessor__namespace,
160
- GeoJson: fileProcessor__namespace,
161
- GeoPackage: fileProcessor__namespace,
162
- "Geoprocessing Package": fileProcessor__namespace,
163
- "Geoprocessing Sample": fileProcessor__namespace,
164
- "Globe Document": fileProcessor__namespace,
165
- "Image Collection": fileProcessor__namespace,
166
- Image: fileProcessor__namespace,
167
- "iWork Keynote": fileProcessor__namespace,
168
- "iWork Numbers": fileProcessor__namespace,
169
- "iWork Pages": fileProcessor__namespace,
170
- "KML Collection": fileProcessor__namespace,
171
- "Layer Package": fileProcessor__namespace,
172
- "Layer Template": fileProcessor__namespace,
173
- Layer: fileProcessor__namespace,
174
- Layout: fileProcessor__namespace,
175
- "Locator Package": fileProcessor__namespace,
176
- "Map Document": fileProcessor__namespace,
177
- "Map Package": fileProcessor__namespace,
178
- "Map Template": fileProcessor__namespace,
179
- "Microsoft Excel": fileProcessor__namespace,
180
- "Microsoft Powerpoint": fileProcessor__namespace,
181
- "Microsoft Word": fileProcessor__namespace,
182
- "Mobile Basemap Package": fileProcessor__namespace,
183
- "Mobile Map Package": fileProcessor__namespace,
184
- "Mobile Scene Package": fileProcessor__namespace,
185
- "Native Application": fileProcessor__namespace,
186
- "Native Application Installer": fileProcessor__namespace,
187
- "Native Application Template": fileProcessor__namespace,
188
- netCDF: fileProcessor__namespace,
189
- "Operation View": fileProcessor__namespace,
190
- "Operations Dashboard Add In": fileProcessor__namespace,
191
- "Operations Dashboard Extension": fileProcessor__namespace,
192
- PDF: fileProcessor__namespace,
193
- "Pro Layer Package": fileProcessor__namespace,
194
- "Pro Layer": fileProcessor__namespace,
195
- "Pro Map Package": fileProcessor__namespace,
196
- "Pro Map": fileProcessor__namespace,
197
- "Pro Report": fileProcessor__namespace,
198
- "Project Package": fileProcessor__namespace,
199
- "Project Template": fileProcessor__namespace,
200
- "Published Map": fileProcessor__namespace,
201
- "Raster function template": fileProcessor__namespace,
202
- "Report Template": fileProcessor__namespace,
203
- "Rule Package": fileProcessor__namespace,
204
- "Scene Document": fileProcessor__namespace,
205
- "Scene Package": fileProcessor__namespace,
206
- "Service Definition": fileProcessor__namespace,
207
- Shapefile: fileProcessor__namespace,
208
- "Statistical Data Collection": fileProcessor__namespace,
209
- Style: fileProcessor__namespace,
210
- "Survey123 Add In": fileProcessor__namespace,
211
- "Symbol Set": fileProcessor__namespace,
212
- "Task File": fileProcessor__namespace,
213
- "Tile Package": fileProcessor__namespace,
214
- "Toolbox Package": fileProcessor__namespace,
215
- "Vector Tile Package": fileProcessor__namespace,
216
- "Viewer Configuration": fileProcessor__namespace,
217
- "Visio Document": fileProcessor__namespace,
218
- "Window Mobile Package": fileProcessor__namespace,
219
- "Windows Mobile Package": fileProcessor__namespace,
220
- "Windows Viewer Add In": fileProcessor__namespace,
221
- "Windows Viewer Configuration": fileProcessor__namespace,
222
- "Workflow Manager Package": fileProcessor__namespace,
223
- ////////////////////////////////////////////////////////
224
- // Testing "types"
225
- Undefined: undefined,
226
- Unsupported: UNSUPPORTED
227
- };
228
-
229
- /** @license
230
- * Copyright 2018 Esri
231
- *
232
- * Licensed under the Apache License, Version 2.0 (the "License");
233
- * you may not use this file except in compliance with the License.
234
- * You may obtain a copy of the License at
235
- *
236
- * http://www.apache.org/licenses/LICENSE-2.0
237
- *
238
- * Unless required by applicable law or agreed to in writing, software
239
- * distributed under the License is distributed on an "AS IS" BASIS,
240
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
241
- * See the License for the specific language governing permissions and
242
- * limitations under the License.
243
- */
244
- // ------------------------------------------------------------------------------------------------------------------ //
245
- /**
246
- * Creates template for an AGO item and its dependencies
247
- *
248
- * @param solutionItemId The solution to contain the item
249
- * @param itemId AGO id string
250
- * @param templateDictionary Hash of facts
251
- * @param srcAuthentication Credentials for requests to source items
252
- * @param destAuthentication Authentication for requesting information from AGO about items to be included in solution item
253
- * @param existingTemplates A collection of AGO item templates that can be referenced by newly-created templates
254
- * @returns A promise which resolves with an array of resources for the item and its dependencies
255
- * @private
256
- */
257
- function createItemTemplate(solutionItemId, itemId, templateDictionary, srcAuthentication, destAuthentication, existingTemplates, itemProgressCallback) {
258
- return new Promise(resolve => {
259
- // Check if item and its dependents are already in list or are queued
260
- if (solutionCommon.findTemplateInList(existingTemplates, itemId)) {
261
- resolve([]);
262
- }
263
- else {
264
- // Add the id as a placeholder to show that it is being fetched
265
- existingTemplates.push(solutionCommon.createPlaceholderTemplate(itemId));
266
- itemProgressCallback(itemId, solutionCommon.EItemProgressStatus.Started, 0);
267
- // Fetch the item
268
- solutionCommon.getItemBase(itemId, srcAuthentication)
269
- .catch(() => {
270
- // If item query fails, try fetching item as a group
271
- // Change its placeholder from an empty type to the Group type so that we can later distinguish
272
- // between items and groups (the base info for a group doesn't include a type property)
273
- solutionCommon.replaceTemplate(existingTemplates, itemId, solutionCommon.createPlaceholderTemplate(itemId, "Group"));
274
- return solutionCommon.getGroupBase(itemId, srcAuthentication);
275
- })
276
- .then(itemInfo => {
277
- itemInfo = solutionCommon.sanitizeJSONAndReportChanges(itemInfo);
278
- // Save the URL as a symbol
279
- if (itemInfo.url) {
280
- templateDictionary[itemInfo.url] = "{{" + itemInfo.id + ".url}}";
281
- itemInfo.origUrl = itemInfo.url;
282
- }
283
- const idTest = /^source-[0-9A-F]{32}/i;
284
- // Remove any source-itemId type keywords
285
- /* istanbul ignore else */
286
- if (Array.isArray(itemInfo.typeKeywords)) {
287
- itemInfo.typeKeywords = itemInfo.typeKeywords.filter(v => idTest.test(v) ? false : true);
288
- }
289
- // Remove any source-itemId tags
290
- /* istanbul ignore else */
291
- if (Array.isArray(itemInfo.tags)) {
292
- itemInfo.tags = itemInfo.tags.filter(v => idTest.test(v) ? false : true);
293
- }
294
- const placeholder = solutionCommon.findTemplateInList(existingTemplates, itemId);
295
- let itemType = placeholder.type;
296
- if (!itemType) {
297
- // Groups have this defined when their placeholder is created
298
- itemType = itemInfo.type;
299
- placeholder.type = itemType;
300
- }
301
- if (!itemInfo.type) {
302
- itemInfo.type = itemType; // Groups don't have this property, so we'll patch it in
303
- }
304
- placeholder.item = {
305
- ...itemInfo
306
- };
307
- // Interrupt process if progress callback returns `false`
308
- if (!itemProgressCallback(itemId, solutionCommon.EItemProgressStatus.Created, 1)) {
309
- itemProgressCallback(itemId, solutionCommon.EItemProgressStatus.Cancelled, 1);
310
- resolve(solutionCommon.fail("Cancelled"));
311
- return;
312
- }
313
- const itemHandler = moduleMap[itemType];
314
- if (!itemHandler || itemHandler === UNSUPPORTED) {
315
- if (itemHandler === UNSUPPORTED) {
316
- itemProgressCallback(itemId, solutionCommon.EItemProgressStatus.Ignored, 1);
317
- resolve([]);
318
- }
319
- else {
320
- itemProgressCallback(itemId, solutionCommon.EItemProgressStatus.Failed, 1);
321
- placeholder.properties["failed"] = true;
322
- solutionCommon.replaceTemplate(existingTemplates, itemId, placeholder);
323
- resolve(solutionCommon.fail("The type of AGO item " +
324
- itemId +
325
- " ('" +
326
- itemType +
327
- "') is not supported at this time"));
328
- }
329
- }
330
- else {
331
- // Handle original Story Maps with next-gen Story Maps
332
- /* istanbul ignore else */
333
- /* Not yet supported
334
- if (storyMap.isAStoryMap(itemType, itemInfo.url)) {
335
- itemHandler = storyMap;
336
- } */
337
- // Delegate the creation of the item to the handler
338
- itemHandler
339
- .convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary)
340
- .then(itemTemplate => {
341
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
342
- solutionCommon.getItemResourcesPaths(itemTemplate, solutionItemId, srcAuthentication, solutionCommon.SolutionTemplateFormatVersion).then((resourceItemFilePaths) => {
343
- itemTemplate.item.thumbnail = null; // not needed in this property; handled as a resource
344
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
345
- solutionCommon.getItemResourcesFilesFromPaths(resourceItemFilePaths, srcAuthentication).then((resourceItemFiles) => {
346
- // update the template's resources
347
- itemTemplate.resources = itemTemplate.resources.concat(resourceItemFiles.map((file) => file.folder + "/" + file.filename));
348
- // Set the value keyed by the id to the created template, replacing the placeholder template
349
- solutionCommon.replaceTemplate(existingTemplates, itemTemplate.itemId, itemTemplate);
350
- // Trace item dependencies
351
- if (itemTemplate.dependencies.length === 0) {
352
- itemProgressCallback(itemId, solutionCommon.EItemProgressStatus.Finished, 1);
353
- resolve(resourceItemFiles);
354
- }
355
- else {
356
- // Get its dependencies, asking each to get its dependents via
357
- // recursive calls to this function
358
- const dependentDfds = [];
359
- itemTemplate.dependencies.forEach(dependentId => {
360
- if (!solutionCommon.findTemplateInList(existingTemplates, dependentId)) {
361
- dependentDfds.push(createItemTemplate(solutionItemId, dependentId, templateDictionary, srcAuthentication, destAuthentication, existingTemplates, itemProgressCallback));
362
- }
363
- });
364
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
365
- Promise.all(dependentDfds).then((dependentResourceItemFiles) => {
366
- // Templatization of item and its dependencies done
367
- itemProgressCallback(itemId, solutionCommon.EItemProgressStatus.Finished, 1);
368
- resourceItemFiles = dependentResourceItemFiles.reduce((accumulator, currentValue) => accumulator.concat(currentValue), resourceItemFiles);
369
- resolve(resourceItemFiles);
370
- });
371
- }
372
- });
373
- });
374
- }, error => {
375
- placeholder.properties["error"] = JSON.stringify(error);
376
- solutionCommon.replaceTemplate(existingTemplates, itemId, placeholder);
377
- itemProgressCallback(itemId, solutionCommon.EItemProgressStatus.Failed, 1);
378
- resolve([]);
379
- });
380
- }
381
- },
382
- // Id not found or item is not accessible
383
- () => {
384
- // mock hasInvalidDesignations so this will be processed at the end
385
- // as we do with living atlas layers
386
- const t = solutionCommon.findTemplateInList(existingTemplates, itemId);
387
- t.properties.hasInvalidDesignations = true;
388
- // Skip items that we cannot fetch per issue #859
389
- // Use finished rather than ignored
390
- // ignored will cause the template to be removed before we can check for hasInvalidDesignations
391
- itemProgressCallback(itemId, solutionCommon.EItemProgressStatus.Finished, 0);
392
- resolve([]);
393
- });
394
- }
395
- });
396
- }
397
- /**
398
- * Templatizes field references within specific template types.
399
- * Currently only handles web applications
400
- *
401
- * @param templates List of solution templates
402
- * @returns A list of templates that have templatized field references
403
- */
404
- function postProcessFieldReferences(templates) {
405
- const datasourceInfos = _getDatasourceInfos(templates);
406
- const templateTypeHash = _getTemplateTypeHash(templates);
407
- return templates.map(template => {
408
- /* istanbul ignore else */
409
- if (template.type === "Web Mapping Application" ||
410
- template.type === "Dashboard" ||
411
- template.type === "Web Map") {
412
- const webMapFSDependencies = _getWebMapFSDependencies(template, templateTypeHash);
413
- const itemHandler = moduleMap[template.item.type];
414
- /* istanbul ignore else */
415
- if (itemHandler) {
416
- const dependencies = webMapFSDependencies.concat(template.dependencies);
417
- let dependantDatasources = datasourceInfos.filter(ds => {
418
- if (dependencies.indexOf(ds.itemId) > -1) {
419
- return ds;
420
- }
421
- });
422
- dependantDatasources = _addMapLayerIds(dependantDatasources, templateTypeHash);
423
- if (dependantDatasources.length > 0) {
424
- template = itemHandler.postProcessFieldReferences(template, dependantDatasources, template.item.type);
425
- }
426
- }
427
- }
428
- return template;
429
- });
430
- }
431
- // ------------------------------------------------------------------------------------------------------------------ //
432
- /**
433
- * Get common properties that will support the templatization of field references
434
- *
435
- * @param templates List of solution templates
436
- * @returns A list of IDataSourceInfo objects with key properties
437
- * @private
438
- */
439
- function _getDatasourceInfos(templates) {
440
- const datasourceInfos = [];
441
- templates.forEach(t => {
442
- if (t.type === "Feature Service") {
443
- const layers = hubCommon.getProp(t, "properties.layers") || [];
444
- const tables = hubCommon.getProp(t, "properties.tables") || [];
445
- const layersAndTables = layers.concat(tables);
446
- layersAndTables.forEach(obj => {
447
- /* istanbul ignore else */
448
- if (!solutionCommon.hasDatasource(datasourceInfos, t.itemId, obj.id)) {
449
- datasourceInfos.push({
450
- itemId: t.itemId,
451
- layerId: obj.id,
452
- fields: obj.fields,
453
- basePath: t.itemId + ".layer" + obj.id + ".fields",
454
- url: hubCommon.getProp(t, "item.url"),
455
- ids: [],
456
- relationships: obj.relationships || [],
457
- adminLayerInfo: obj.adminLayerInfo || {}
458
- });
459
- }
460
- });
461
- }
462
- });
463
- return datasourceInfos;
464
- }
465
- /**
466
- * Creates a simple lookup object to quickly understand an items type and dependencies
467
- * and associated web map layer ids based on itemId
468
- *
469
- * @param templates List of solution templates
470
- * @returns The lookup object with type, dependencies, and webmap layer info
471
- * @private
472
- */
473
- function _getTemplateTypeHash(templates) {
474
- const templateTypeHash = {};
475
- templates.forEach(template => {
476
- templateTypeHash[template.itemId] = {
477
- type: template.type,
478
- dependencies: template.dependencies
479
- };
480
- if (template.type === "Web Map") {
481
- _updateWebMapHashInfo(template, templateTypeHash[template.itemId]);
482
- }
483
- });
484
- return templateTypeHash;
485
- }
486
- /**
487
- * Updates the lookup object with webmap layer info
488
- * so we can know the id used within a map for a given feature service
489
- *
490
- * @param template A webmap solution template
491
- * @returns The lookup object with webmap layer info added
492
- * @private
493
- */
494
- function _updateWebMapHashInfo(template, hashItem) {
495
- const operationalLayers = hubCommon.getProp(template, "data.operationalLayers") || [];
496
- const tables = hubCommon.getProp(template, "data.tables") || [];
497
- const layersAndTables = operationalLayers.concat(tables);
498
- if (layersAndTables && layersAndTables.length > 0) {
499
- hashItem.layersAndTables = [];
500
- layersAndTables.forEach(layer => {
501
- const obj = {};
502
- let itemId;
503
- /* istanbul ignore else */
504
- if (layer.itemId) {
505
- itemId = layer.itemId;
506
- }
507
- /* istanbul ignore else */
508
- if (itemId) {
509
- obj[solutionCommon.cleanLayerBasedItemId(itemId)] = {
510
- id: layer.id,
511
- url: layer.url
512
- };
513
- hashItem.layersAndTables.push(obj);
514
- }
515
- });
516
- }
517
- }
518
- /**
519
- * Updates a templatized datasource URL with a layer id.
520
- *
521
- * @param dataSourceUrl Templatized datasource URL
522
- * @param layerId Layer id
523
- * @returns string Amended datasource URL
524
- * @private
525
- */
526
- function _addLayerIdToDatasourceUrl(datasourceUrl, layerId) {
527
- return datasourceUrl && !isNaN(layerId)
528
- ? datasourceUrl.replace(/[.]/, ".layer" + layerId + ".")
529
- : "";
530
- }
531
- /**
532
- * Updates the datasource info objects by passing the webmap layer IDs from the lookup hash
533
- * to the underlying feature service datasource infos
534
- *
535
- * @param datasourceInfos A webmap solution template
536
- * @param templateTypeHash A simple lookup object populated with key item info
537
- * @returns The updated datasource infos
538
- * @private
539
- */
540
- function _addMapLayerIds(datasourceInfos, templateTypeHash) {
541
- const webMapIds = Object.keys(templateTypeHash).filter(k => {
542
- if (templateTypeHash[k].type === "Web Map") {
543
- return templateTypeHash[k];
544
- }
545
- });
546
- return datasourceInfos.map(ds => {
547
- webMapIds.forEach(webMapId => {
548
- templateTypeHash[webMapId].layersAndTables.forEach((opLayer) => {
549
- const opLayerInfo = opLayer[ds.itemId];
550
- const url = _addLayerIdToDatasourceUrl(ds.url, ds.layerId);
551
- if (opLayerInfo &&
552
- url === opLayerInfo.url &&
553
- ds.ids.indexOf(opLayerInfo.id) < 0) {
554
- ds.ids.push(opLayerInfo.id);
555
- }
556
- });
557
- });
558
- return ds;
559
- });
560
- }
561
- /**
562
- * Get feature service item IDs from applications webmaps
563
- * As they are not explict dependencies of the application but are needed for field references
564
- *
565
- * @param template A webmap solution template
566
- * @param templateTypeHash A simple lookup object populated with key item info
567
- * @returns A lsit of feature service item IDs
568
- * @private
569
- */
570
- function _getWebMapFSDependencies(template, templateTypeHash) {
571
- const webMapFSDependencies = [];
572
- template.dependencies.forEach(dep => {
573
- const depObj = templateTypeHash[dep];
574
- if (depObj.type === "Web Map") {
575
- depObj.dependencies.forEach((depObjDependency) => {
576
- /* istanbul ignore else */
577
- if (templateTypeHash[depObjDependency].type === "Feature Service") {
578
- webMapFSDependencies.push(depObjDependency);
579
- }
580
- });
581
- }
582
- });
583
- return webMapFSDependencies;
584
- }
585
-
586
- /** @license
587
- * Copyright 2022 Esri
588
- *
589
- * Licensed under the Apache License, Version 2.0 (the "License");
590
- * you may not use this file except in compliance with the License.
591
- * You may obtain a copy of the License at
592
- *
593
- * http://www.apache.org/licenses/LICENSE-2.0
594
- *
595
- * Unless required by applicable law or agreed to in writing, software
596
- * distributed under the License is distributed on an "AS IS" BASIS,
597
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
598
- * See the License for the specific language governing permissions and
599
- * limitations under the License.
600
- */
601
- /**
602
- * Extracts resource data files from templates.
603
- *
604
- * @param templates List of templates to examine
605
- *
606
- * @return List of resource data files found in supplied templates
607
- */
608
- function getDataFilesFromTemplates(templates) {
609
- const resourceItemFiles = [];
610
- templates.forEach((template) => {
611
- if (template.dataFile) {
612
- resourceItemFiles.push(template.dataFile);
613
- }
614
- });
615
- return resourceItemFiles;
616
- }
617
- /**
618
- * Removes data files from templates.
619
- *
620
- * @param templates List of templates to modify
621
- */
622
- function removeDataFilesFromTemplates(templates) {
623
- templates.forEach((template) => {
624
- if (template.dataFile) {
625
- delete template.dataFile;
626
- }
627
- });
628
- }
629
-
630
- /** @license
631
- * Copyright 2020 Esri
632
- *
633
- * Licensed under the Apache License, Version 2.0 (the "License");
634
- * you may not use this file except in compliance with the License.
635
- * You may obtain a copy of the License at
636
- *
637
- * http://www.apache.org/licenses/LICENSE-2.0
638
- *
639
- * Unless required by applicable law or agreed to in writing, software
640
- * distributed under the License is distributed on an "AS IS" BASIS,
641
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
642
- * See the License for the specific language governing permissions and
643
- * limitations under the License.
644
- */
645
- /**
646
- * Adds a list of AGO item ids to a solution item.
647
- *
648
- * @param solutionItemId AGO id of solution to receive items
649
- * @param options Customizations for creating the solution
650
- * @param srcAuthentication Credentials for requests to source items
651
- * @param destAuthentication Credentials for the requests to destination solution
652
- * @returns A promise that resolves with the AGO id of the updated solution
653
- * @internal
654
- */
655
- function addContentToSolution(solutionItemId, options, srcAuthentication, destAuthentication) {
656
- return new Promise((resolve, reject) => {
657
- if (!options.itemIds || options.itemIds.length === 0) {
658
- resolve(solutionItemId);
659
- return;
660
- }
661
- // Prepare feedback mechanism
662
- let totalEstimatedCost = 2 * options.itemIds.length + 1; // solution items, plus avoid divide by 0
663
- let percentDone = 16; // allow for previous creation work
664
- let progressPercentStep = (95 - percentDone) / totalEstimatedCost; // leave some % for caller for wrapup
665
- const failedItemIds = [];
666
- let totalExpended = 0;
667
- let statusOK = true;
668
- const itemProgressCallback = (itemId, status, costUsed) => {
669
- // ---------------------------------------------------------------------------------------------------------------
670
- if (options.itemIds.indexOf(itemId) < 0) {
671
- // New item--a dependency that wasn't in the supplied list of itemIds; add it to the list
672
- // and recalculate the progress percent step based on how much progress remains to be done
673
- options.itemIds.push(itemId);
674
- totalEstimatedCost += 2;
675
- progressPercentStep =
676
- (95 - percentDone) / (totalEstimatedCost - totalExpended);
677
- }
678
- totalExpended += costUsed;
679
- percentDone += progressPercentStep * costUsed;
680
- if (options.progressCallback) {
681
- options.progressCallback(Math.round(percentDone), options.jobId);
682
- }
683
- /* istanbul ignore if */
684
- if (options.consoleProgress) {
685
- console.log(Date.now(), itemId, options.jobId ?? "", solutionCommon.SItemProgressStatus[status], percentDone.toFixed(0) + "%", costUsed);
686
- }
687
- if (status === solutionCommon.EItemProgressStatus.Failed) {
688
- let error = "";
689
- solutionTemplates.some(t => {
690
- /* istanbul ignore else */
691
- if (t.itemId === itemId) {
692
- /* istanbul ignore else */
693
- if (hubCommon.getProp(t, "properties.error")) {
694
- error = t.properties.error;
695
- try {
696
- // parse for better console logging if we can
697
- error = JSON.parse(error);
698
- }
699
- catch (e) {
700
- /* istanbul ignore next */
701
- // do nothing and show the error as is
702
- }
703
- }
704
- return true;
705
- }
706
- });
707
- solutionCommon.removeTemplate(solutionTemplates, itemId);
708
- if (failedItemIds.indexOf(itemId) < 0) {
709
- failedItemIds.push(itemId);
710
- }
711
- statusOK = false;
712
- }
713
- else if (status === solutionCommon.EItemProgressStatus.Ignored) {
714
- solutionCommon.removeTemplate(solutionTemplates, itemId);
715
- }
716
- return statusOK;
717
- // ---------------------------------------------------------------------------------------------------------------
718
- };
719
- // Replacement dictionary and created templates
720
- const templateDictionary = options.templateDictionary ?? {};
721
- let solutionTemplates = [];
722
- // Handle a list of one or more AGO ids by stepping through the list
723
- // and calling this function recursively
724
- const getItemsPromise = [];
725
- options.itemIds.forEach(itemId => {
726
- const createDef = createItemTemplate(solutionItemId, itemId, templateDictionary, srcAuthentication, destAuthentication, solutionTemplates, itemProgressCallback);
727
- getItemsPromise.push(createDef);
728
- });
729
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
730
- Promise.all(getItemsPromise).then((multipleResourceItemFiles) => {
731
- if (failedItemIds.length > 0) {
732
- reject(solutionCommon.failWithIds(failedItemIds, "One or more items cannot be converted into templates"));
733
- }
734
- else {
735
- if (solutionTemplates.length > 0) {
736
- // Coalesce the resource file paths from the created templates
737
- let resourceItemFiles = multipleResourceItemFiles.reduce((accumulator, currentValue) => accumulator.concat(currentValue), []);
738
- // Extract resource data files from templates
739
- resourceItemFiles = resourceItemFiles.concat(getDataFilesFromTemplates(solutionTemplates));
740
- // test for and update group dependencies and other post-processing
741
- solutionTemplates = _postProcessGroupDependencies(solutionTemplates);
742
- solutionTemplates = solutionCommon.postProcessWorkforceTemplates(solutionTemplates);
743
- // Filter out any resources from items that have been removed from the templates, such as
744
- // Living Atlas layers
745
- solutionTemplates = _postProcessIgnoredItems(solutionTemplates, templateDictionary);
746
- const templateIds = solutionTemplates.map(template => template.itemId);
747
- // Coalesce the resource file paths from the created templates
748
- resourceItemFiles = resourceItemFiles.filter(file => templateIds.includes(file.itemId));
749
- // Send the accumulated resources to the solution item
750
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
751
- solutionCommon.copyFilesToStorageItem(resourceItemFiles, solutionItemId, destAuthentication).then(() => {
752
- // Remove data files from templates--no longer needed
753
- removeDataFilesFromTemplates(solutionTemplates);
754
- _templatizeSolutionIds(solutionTemplates);
755
- _simplifyUrlsInItemDescriptions(solutionTemplates);
756
- _replaceDictionaryItemsInObject(templateDictionary, solutionTemplates);
757
- _templatizeOrgUrl(solutionTemplates, destAuthentication).then(solutionTemplates2 => {
758
- // Update solution item with its data JSON
759
- const solutionData = {
760
- metadata: { version: solutionCommon.SolutionTemplateFormatVersion },
761
- templates: options.templatizeFields
762
- ? postProcessFieldReferences(solutionTemplates2)
763
- : solutionTemplates2
764
- };
765
- const itemInfo = {
766
- id: solutionItemId,
767
- text: solutionData
768
- };
769
- solutionCommon.updateItem(itemInfo, destAuthentication).then(() => {
770
- resolve(solutionItemId);
771
- }, reject);
772
- }, reject);
773
- });
774
- }
775
- else {
776
- resolve(solutionItemId);
777
- }
778
- }
779
- });
780
- });
781
- }
782
- // ------------------------------------------------------------------------------------------------------------------ //
783
- /**
784
- * Gets the dependencies of an item by merging its dependencies list with item references in template variables.
785
- *
786
- * @param template Template to examine
787
- * @returns List of dependency ids
788
- * @private
789
- */
790
- function _getDependencies(template) {
791
- // Get all dependencies
792
- let deps = template.dependencies.concat(_getIdsOutOfTemplateVariables(_getTemplateVariables(JSON.stringify(template.data))));
793
- // Remove duplicates and self-references
794
- deps.sort();
795
- deps = deps.filter((elem, index, array) => {
796
- if (elem === template.itemId) {
797
- return false;
798
- }
799
- else if (index > 0) {
800
- return elem !== array[index - 1];
801
- }
802
- else {
803
- return true;
804
- }
805
- });
806
- return deps;
807
- }
808
- /**
809
- * Extracts AGO ids out of template variables.
810
- *
811
- * @param variables List of template variables to examine
812
- * @returns List of AGO ids referenced in `variables`
813
- * @private
814
- */
815
- function _getIdsOutOfTemplateVariables(variables) {
816
- return variables
817
- .map(variable => {
818
- const idList = variable.match(/[0-9A-F]{32}/i); // is it a guid?
819
- if (idList) {
820
- return idList[0];
821
- }
822
- else {
823
- return null;
824
- }
825
- })
826
- .filter(variable => !!variable);
827
- }
828
- /**
829
- * Creates a list of item URLs.
830
- *
831
- * @param templates Templates to check for URLs
832
- * @returns List of URLs
833
- * @private
834
- */
835
- function _getSolutionItemUrls(templates) {
836
- const solutionUrls = [];
837
- templates.forEach(template => {
838
- /* istanbul ignore else */
839
- if (template.item.origUrl) {
840
- solutionUrls.push([template.itemId, template.item.origUrl]);
841
- }
842
- });
843
- return solutionUrls;
844
- }
845
- /**
846
- * Extracts template variables out of a string.
847
- *
848
- * @param text String to examine
849
- * @returns List of template variables found in string
850
- * @private
851
- */
852
- function _getTemplateVariables(text) {
853
- return (text.match(/{{[a-z0-9.]*}}/gi) || []) // find variable
854
- .map(variable => variable.substring(2, variable.length - 2)); // remove "{{" & "}}"
855
- }
856
- /**
857
- * Update the items dependencies and groups arrays
858
- *
859
- * @param templates The array of templates to evaluate
860
- * @returns Updated version of the templates
861
- * @private
862
- */
863
- function _postProcessGroupDependencies(templates) {
864
- return templates.map((template) => {
865
- if (template.type === "Group") {
866
- const id = template.itemId;
867
- // remove group dependencies if we find a circular dependency with one of its items
868
- let removeDependencies = false;
869
- // before we remove update each dependants groups array
870
- template.dependencies.forEach(dependencyId => {
871
- const dependantTemplate = solutionCommon.getTemplateById(templates, dependencyId);
872
- // Not all items shared to the group will exist in the templates array
873
- // i.e. Hub Initiative items or any other unsupported types
874
- if (dependantTemplate) {
875
- // check if the group is in the dependantTemplate's list of dependencies
876
- const gIndex = hubCommon.getWithDefault(dependantTemplate, "dependencies", []).indexOf(id);
877
- /* istanbul ignore else */
878
- if (gIndex > -1) {
879
- removeDependencies = true;
880
- }
881
- // if the dependant template does not have the group id
882
- // in it's groups array, add it
883
- const groups = hubCommon.getWithDefault(dependantTemplate, "groups", []);
884
- if (groups.indexOf(id) === -1) {
885
- groups.push(id);
886
- dependantTemplate.groups = groups;
887
- }
888
- }
889
- });
890
- if (removeDependencies) {
891
- template.dependencies = [];
892
- }
893
- }
894
- return template;
895
- });
896
- }
897
- /**
898
- * Check for feature service items that have been flagged for invalid designations.
899
- * Remove templates that have invalid designations from the solution item and other item dependencies.
900
- * Clean up any references to items with invalid designations in the other templates.
901
- *
902
- * @param templates The array of templates to evaluate
903
- * @param templateDictionary Hash of key details used for variable replacement
904
- * @returns Updated version of the templates
905
- * @private
906
- */
907
- function _postProcessIgnoredItems(templates, templateDictionary) {
908
- // replace in template
909
- const updateDictionary = templates.reduce((result, template) => {
910
- const invalidDes = template.properties.hasInvalidDesignations;
911
- const unreachableVal = hubCommon.getProp(templateDictionary, `${solutionCommon.UNREACHABLE}.${template.itemId}`);
912
- if (invalidDes && unreachableVal && Object.keys(template.data).length < 1) {
913
- template.data[template.itemId] = unreachableVal;
914
- }
915
- return invalidDes ? Object.assign(result, template.data) : result;
916
- }, {});
917
- Object.keys(updateDictionary).forEach(k => {
918
- solutionCommon.removeTemplate(templates, k);
919
- templates = templates.map(t => {
920
- t.dependencies = t.dependencies.filter(id => id !== k);
921
- return solutionCommon.replaceInTemplate(t, updateDictionary);
922
- });
923
- });
924
- return templates;
925
- }
926
- /**
927
- * Recursively runs through an object to find and replace any strings found in a dictionary.
928
- *
929
- * @param templateDictionary Hash of things to be replaced
930
- * @param obj Object to be examined
931
- * @private
932
- */
933
- function _replaceDictionaryItemsInObject(hash, obj) {
934
- /* istanbul ignore else */
935
- if (obj) {
936
- Object.keys(obj).forEach(prop => {
937
- const propObj = obj[prop];
938
- if (propObj) {
939
- if (typeof propObj === "object") {
940
- _replaceDictionaryItemsInObject(hash, propObj);
941
- }
942
- else if (typeof propObj === "string") {
943
- obj[prop] = hash[propObj] || propObj;
944
- }
945
- }
946
- });
947
- }
948
- return obj;
949
- }
950
- /**
951
- * Recursively runs through an object to find and templatize any remaining references to solution's items.
952
- *
953
- * @param ids Ids to be replaced in strings found in object
954
- * @param obj Object to be examined
955
- * @private
956
- */
957
- function _replaceRemainingIdsInObject(ids, obj) {
958
- /* istanbul ignore else */
959
- if (obj) {
960
- Object.keys(obj).forEach(prop => {
961
- const propObj = obj[prop];
962
- if (propObj) {
963
- if (typeof propObj === "object") {
964
- _replaceRemainingIdsInObject(ids, propObj);
965
- }
966
- else if (typeof propObj === "string") {
967
- obj[prop] = _replaceRemainingIdsInString(ids, propObj);
968
- }
969
- }
970
- });
971
- }
972
- return obj;
973
- }
974
- /**
975
- * Templatizes ids from a list in a string if they're not already templatized.
976
- *
977
- * @param ids Ids to be replaced in source string
978
- * @param str Source string to be examined
979
- * @returns A copy of the source string with any templatization changes
980
- * @private
981
- */
982
- function _replaceRemainingIdsInString(ids, str) {
983
- let updatedStr = str;
984
- const untemplatizedIds = solutionCommon.getIDs(str);
985
- if (untemplatizedIds.length > 0) {
986
- untemplatizedIds.forEach(id => {
987
- if (ids.includes(id)) {
988
- const re = new RegExp("({*)" + id, "gi");
989
- updatedStr = updatedStr.replace(re, match => match.indexOf("{{") < 0
990
- ? "{{" + id.replace("{", "") + ".itemId}}"
991
- : match);
992
- }
993
- });
994
- }
995
- return updatedStr;
996
- }
997
- /**
998
- * Finds and templatizes any URLs in solution items' descriptions.
999
- *
1000
- * @param templates The array of templates to evaluate, modified in place
1001
- * @private
1002
- */
1003
- function _simplifyUrlsInItemDescriptions(templates) {
1004
- // Get the urls in the solution along with their item ids & convert the id into the form
1005
- // "{{fcb2bf2837a6404ebb418a1f805f976a.url}}"
1006
- const solutionUrls = _getSolutionItemUrls(templates).map(idUrl => [
1007
- "{{" + idUrl[0] + ".url}}",
1008
- idUrl[1]
1009
- ]);
1010
- /* istanbul ignore else */
1011
- if (solutionUrls.length > 0) {
1012
- // Make the replacements
1013
- templates.forEach(template => {
1014
- solutionUrls.forEach(
1015
- // TypeScript for es2015 doesn't have a definition for `replaceAll`
1016
- idUrl => {
1017
- /* istanbul ignore else */
1018
- if (template.item.description) {
1019
- template.item.description = template.item
1020
- .description.replaceAll(idUrl[1], idUrl[0]);
1021
- }
1022
- });
1023
- });
1024
- }
1025
- }
1026
- /**
1027
- * Templatizes occurrences of the URL to the user's organization in the `item` and `data` template sections.
1028
- *
1029
- * @param templates The array of templates to evaluate; templates is modified in place
1030
- * @param destAuthentication Credentials for request organization info
1031
- * @returns Promise resolving with `templates`
1032
- * @private
1033
- */
1034
- function _templatizeOrgUrl(templates, destAuthentication) {
1035
- return new Promise((resolve, reject) => {
1036
- // Get the org's URL
1037
- solutionCommon.getPortal(null, destAuthentication).then(org => {
1038
- const orgUrl = "https://" + org.urlKey + "." + org.customBaseUrl;
1039
- const templatizedOrgUrl = "{{portalBaseUrl}}";
1040
- // Cycle through each of the items in the template and scan the `item` and `data` sections of each for replacements
1041
- templates.forEach((template) => {
1042
- solutionCommon.globalStringReplace(template.item, new RegExp(orgUrl, "gi"), templatizedOrgUrl);
1043
- solutionCommon.globalStringReplace(template.data, new RegExp(orgUrl, "gi"), templatizedOrgUrl);
1044
- });
1045
- resolve(templates);
1046
- }, reject);
1047
- });
1048
- }
1049
- /**
1050
- * Finds and templatizes any references to solution's items.
1051
- *
1052
- * @param templates The array of templates to evaluate, modified in place
1053
- * @private
1054
- */
1055
- function _templatizeSolutionIds(templates) {
1056
- // Get the ids in the solution
1057
- const solutionIds = templates.map((template) => template.itemId);
1058
- // Cycle through each of the items in the template and
1059
- // 1. templatize untemplatized ids in our solution in the `item` and `data` sections;
1060
- // 2. update the `dependencies` section
1061
- templates.forEach((template) => {
1062
- _replaceRemainingIdsInObject(solutionIds, template.item);
1063
- _replaceRemainingIdsInObject(solutionIds, template.data);
1064
- /* istanbul ignore else */
1065
- if (template.type !== "Group" && !solutionCommon.isWorkforceProject(template)) {
1066
- template.dependencies = _getDependencies(template);
1067
- }
1068
- });
1069
- }
1070
-
1071
- /** @license
1072
- * Copyright 2018 Esri
1073
- *
1074
- * Licensed under the Apache License, Version 2.0 (the "License");
1075
- * you may not use this file except in compliance with the License.
1076
- * You may obtain a copy of the License at
1077
- *
1078
- * http://www.apache.org/licenses/LICENSE-2.0
1079
- *
1080
- * Unless required by applicable law or agreed to in writing, software
1081
- * distributed under the License is distributed on an "AS IS" BASIS,
1082
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1083
- * See the License for the specific language governing permissions and
1084
- * limitations under the License.
1085
- */
1086
- // Simple no-op to clean up progressCallback management
1087
- const noOp = () => { };
1088
- /**
1089
- * Creates a solution item.
1090
- *
1091
- * @param sourceId AGO id of group whose contents are to be added to solution or of an item to convert into a solution
1092
- * @param srcAuthentication Credentials for requests to source items
1093
- * @param destAuthentication Credentials for the requests to destination solution
1094
- * @param options Customizations for creating the solution
1095
- * @returns A promise that resolves with the AGO id of the new solution
1096
- */
1097
- function createSolution(sourceId, srcAuthentication, destAuthentication, options) {
1098
- const createOptions = options || {};
1099
- const progressCb = createOptions.progressCallback || noOp;
1100
- createOptions.templateDictionary = Object.assign({}, createOptions.templateDictionary);
1101
- progressCb(1); // let the caller know that we've started
1102
- // Assume that source is a group and try to get group's information
1103
- return Promise.all([
1104
- solutionCommon.getGroupBase(sourceId, srcAuthentication),
1105
- solutionCommon.getGroupContents(sourceId, srcAuthentication),
1106
- solutionCommon.getVelocityUrlBase(srcAuthentication, createOptions.templateDictionary)
1107
- ])
1108
- .then(
1109
- // Group fetches worked; assumption was correct
1110
- responses => {
1111
- createOptions.itemIds = responses[1];
1112
- progressCb(15);
1113
- return new Promise(resolve => {
1114
- // Update the createOptions with values from the group
1115
- resolve(_applySourceToCreateOptions(createOptions, responses[0], srcAuthentication, true));
1116
- });
1117
- },
1118
- // Assumption incorrect; try source as an item
1119
- () => {
1120
- return new Promise((resolve, reject) => {
1121
- createOptions.itemIds = [sourceId];
1122
- solutionCommon.getItemBase(sourceId, srcAuthentication).then(
1123
- // Update the createOptions with values from the item
1124
- itemBase => resolve(_applySourceToCreateOptions(createOptions, itemBase, srcAuthentication, false)), reject);
1125
- });
1126
- })
1127
- .then(createOptions => {
1128
- return new Promise((resolve, reject) => {
1129
- Promise.all([
1130
- solutionCommon.getPortal("", srcAuthentication),
1131
- solutionCommon.getUser(srcAuthentication)
1132
- ]).then(responses => {
1133
- // check tracking
1134
- const [portalResponse, userResponse] = responses;
1135
- solutionCommon.setLocationTrackingEnabled(portalResponse, userResponse, createOptions.templateDictionary);
1136
- resolve(createOptions);
1137
- }, reject);
1138
- });
1139
- })
1140
- .then(
1141
- // Use a copy of the thumbnail rather than a URL to it
1142
- createOptions => {
1143
- return _addThumbnailFileToCreateOptions(createOptions, srcAuthentication);
1144
- })
1145
- .then(
1146
- // Create a solution
1147
- createOptions => {
1148
- return _createSolutionFromItemIds(createOptions, srcAuthentication, destAuthentication);
1149
- })
1150
- .then(
1151
- // Successfully created solution
1152
- createdSolutionId => {
1153
- progressCb(100); // finished
1154
- return createdSolutionId;
1155
- },
1156
- // Error fetching group, group contents, or item, or error creating solution from ids
1157
- error => {
1158
- progressCb(1);
1159
- console.error(error);
1160
- throw error;
1161
- });
1162
- }
1163
- /**
1164
- * Update the createOptions with the group properties
1165
- *
1166
- * @param createOptions
1167
- * @param sourceInfo
1168
- * @param authentication
1169
- * @param isGroup Boolean to indicate if the files are associated with a group or item
1170
- * @private
1171
- */
1172
- function _applySourceToCreateOptions(createOptions, sourceInfo, srcAuthentication, isGroup = false) {
1173
- // Create a solution from the group's or item's contents,
1174
- // using the group's or item's information as defaults for the solution item
1175
- ["title", "snippet", "description", "tags"].forEach(prop => {
1176
- createOptions[prop] = createOptions[prop] ?? sourceInfo[prop];
1177
- });
1178
- if (!createOptions.thumbnailurl && sourceInfo.thumbnail) {
1179
- // Get the full path to the thumbnail
1180
- createOptions.thumbnailurl = solutionCommon.generateSourceThumbnailUrl(srcAuthentication.portal, sourceInfo.id, sourceInfo.thumbnail, isGroup);
1181
- delete sourceInfo.thumbnail;
1182
- }
1183
- return createOptions;
1184
- }
1185
- /**
1186
- * Update the createOptions with the thumbnail file
1187
- *
1188
- * @param createOptions
1189
- * @param srcAuthentication
1190
- * @private
1191
- */
1192
- function _addThumbnailFileToCreateOptions(createOptions, srcAuthentication) {
1193
- return new Promise(resolve => {
1194
- if (!createOptions.thumbnail && createOptions.thumbnailurl) {
1195
- // Figure out the thumbnail's filename
1196
- const filename = solutionCommon.getFilenameFromUrl(createOptions.thumbnailurl) || "thumbnail";
1197
- const thumbnailurl = solutionCommon.appendQueryParam(createOptions.thumbnailurl, "w=400");
1198
- delete createOptions.thumbnailurl;
1199
- // Fetch the thumbnail
1200
- solutionCommon.getBlobAsFile(thumbnailurl, filename, srcAuthentication).then(thumbnail => {
1201
- createOptions.thumbnail = thumbnail;
1202
- resolve(createOptions);
1203
- }, () => {
1204
- resolve(createOptions);
1205
- });
1206
- }
1207
- else {
1208
- resolve(createOptions);
1209
- }
1210
- });
1211
- }
1212
- /**
1213
- * Creates a solution item using a list of AGO item ids.
1214
- *
1215
- * @param options Customizations for creating the solution
1216
- * @param srcAuthentication Credentials for requests to source items
1217
- * @param destAuthentication Credentials for the requests to destination solution
1218
- * @returns A promise that resolves with the AGO id of the new solution; solution item is deleted if its
1219
- * there is a problem updating it
1220
- * @private
1221
- */
1222
- function _createSolutionFromItemIds(options, srcAuthentication, destAuthentication) {
1223
- let solutionId = "";
1224
- // Create a solution from the list of items
1225
- return _createSolutionItem(destAuthentication, options)
1226
- .then(id => {
1227
- solutionId = id;
1228
- // Add list of items to the new solution
1229
- return addContentToSolution(solutionId, options, srcAuthentication, destAuthentication);
1230
- })
1231
- .catch(addError => {
1232
- // If the solution item got created, delete it
1233
- if (solutionId) {
1234
- const failSafeRemove = hubCommon.failSafe(solutionCommon.removeItem, { success: true });
1235
- return failSafeRemove(solutionId, destAuthentication).then(() => {
1236
- throw addError;
1237
- });
1238
- }
1239
- else {
1240
- throw addError;
1241
- }
1242
- });
1243
- }
1244
- /**
1245
- * Creates an empty solution item.
1246
- *
1247
- * @param authentication Credentials for the request
1248
- * @param options Customizations for creating the solution
1249
- * @returns A promise that resolves with the AGO id of the new solution; solution item is deleted if its
1250
- * there is a problem updating its thumbnail
1251
- * @private
1252
- */
1253
- function _createSolutionItem(authentication, options) {
1254
- const model = _createSolutionItemModel(options);
1255
- // Create new solution item
1256
- delete model.item.thumbnailurl;
1257
- model.item.thumbnail = options?.thumbnail;
1258
- return solutionCommon.createItemWithData(model.item, model.data, authentication, options?.folderId).then(createResponse => {
1259
- return Promise.resolve(createResponse.id);
1260
- });
1261
- }
1262
- /**
1263
- * Create the Solution Item model to be used to create
1264
- * the Solution Item itself
1265
- *
1266
- * @param options
1267
- * @private
1268
- */
1269
- function _createSolutionItemModel(options) {
1270
- // Solution uses all supplied tags but for deploy.* tags; that information goes into properties
1271
- const creationTags = options?.tags ?? [];
1272
- const solutionItem = {
1273
- type: "Solution",
1274
- title: options?.title ?? solutionCommon.createShortId(),
1275
- snippet: options?.snippet ?? "",
1276
- description: options?.description ?? "",
1277
- properties: {
1278
- schemaVersion: solutionCommon.CURRENT_SCHEMA_VERSION
1279
- },
1280
- thumbnailurl: options?.thumbnailurl ?? "",
1281
- tags: creationTags.filter((tag) => !tag.startsWith("deploy.")),
1282
- typeKeywords: ["Solution", "Template"].concat(_getDeploymentProperties(creationTags))
1283
- };
1284
- // ensure that snippet and description are not nefarious
1285
- const sanitizedItem = solutionCommon.sanitizeJSONAndReportChanges(solutionItem);
1286
- const addlKeywords = options?.additionalTypeKeywords || [];
1287
- sanitizedItem.typeKeywords = [].concat(solutionItem.typeKeywords, addlKeywords);
1288
- const solutionData = {
1289
- metadata: {},
1290
- templates: []
1291
- };
1292
- return {
1293
- item: sanitizedItem,
1294
- data: solutionData
1295
- };
1296
- }
1297
- /**
1298
- * Gets the deploy.id and deploy.version tag values.
1299
- *
1300
- * @param tags A list of item tags
1301
- * @returns A list containing the two values found in the tags, or defaulting to a new GUID and "1.0", respectively,
1302
- * as needed
1303
- * @private
1304
- */
1305
- function _getDeploymentProperties(tags) {
1306
- return [
1307
- "solutionid-" +
1308
- (_getDeploymentProperty("deploy.id.", tags) ?? solutionCommon.createLongId()),
1309
- "solutionversion-" +
1310
- (_getDeploymentProperty("deploy.version.", tags) ?? "1.0")
1311
- ];
1312
- }
1313
- /**
1314
- * Searches for a tag that has the specified prefix and returns the rest of the tag following that prefix.
1315
- *
1316
- * @param desiredTagPrefix Tag prefix to look for
1317
- * @param tags A list of item tags
1318
- * @returns The extracted value of the first matching tag or null if a tag with the specified prefix is not found
1319
- * @private
1320
- */
1321
- function _getDeploymentProperty(desiredTagPrefix, tags) {
1322
- const foundTagAsList = tags.filter(tag => tag.startsWith(desiredTagPrefix));
1323
- if (foundTagAsList.length > 0) {
1324
- return foundTagAsList[0].substr(desiredTagPrefix.length);
1325
- }
1326
- else {
1327
- return null;
1328
- }
1329
- }
1330
-
1331
- exports.UNSUPPORTED = UNSUPPORTED;
1332
- exports._addLayerIdToDatasourceUrl = _addLayerIdToDatasourceUrl;
1333
- exports._addMapLayerIds = _addMapLayerIds;
1334
- exports._addThumbnailFileToCreateOptions = _addThumbnailFileToCreateOptions;
1335
- exports._applySourceToCreateOptions = _applySourceToCreateOptions;
1336
- exports._createSolutionFromItemIds = _createSolutionFromItemIds;
1337
- exports._createSolutionItem = _createSolutionItem;
1338
- exports._createSolutionItemModel = _createSolutionItemModel;
1339
- exports._getDatasourceInfos = _getDatasourceInfos;
1340
- exports._getDeploymentProperties = _getDeploymentProperties;
1341
- exports._getDeploymentProperty = _getDeploymentProperty;
1342
- exports._getTemplateTypeHash = _getTemplateTypeHash;
1343
- exports._getWebMapFSDependencies = _getWebMapFSDependencies;
1344
- exports._updateWebMapHashInfo = _updateWebMapHashInfo;
1345
- exports.createItemTemplate = createItemTemplate;
1346
- exports.createSolution = createSolution;
1347
- exports.moduleMap = moduleMap;
1348
- exports.postProcessFieldReferences = postProcessFieldReferences;
1349
-
1350
- Object.defineProperty(exports, '__esModule', { value: true });
1351
-
1352
- }));
1353
- //# sourceMappingURL=creator.umd.js.map