@esri/solution-deployer 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 (38) hide show
  1. package/dist/esm/deploySolutionFromTemplate.js +70 -66
  2. package/dist/esm/deploySolutionFromTemplate.js.map +1 -1
  3. package/dist/esm/deploySolutionItems.js +159 -166
  4. package/dist/esm/deploySolutionItems.js.map +1 -1
  5. package/dist/esm/deployer.js +13 -14
  6. package/dist/esm/deployer.js.map +1 -1
  7. package/dist/esm/deployerUtils.js +17 -22
  8. package/dist/esm/deployerUtils.js.map +1 -1
  9. package/dist/esm/helpers/post-process.js +12 -14
  10. package/dist/esm/helpers/post-process.js.map +1 -1
  11. package/dist/esm/helpers/share-templates-to-groups.js +29 -6
  12. package/dist/esm/helpers/share-templates-to-groups.js.map +1 -1
  13. package/dist/esm/helpers/sortTemplates.js +2 -4
  14. package/dist/esm/helpers/sortTemplates.js.map +1 -1
  15. package/dist/esm/module-map.js +2 -2
  16. package/dist/esm/module-map.js.map +1 -1
  17. package/dist/node/deploySolutionFromTemplate.js +76 -72
  18. package/dist/node/deploySolutionFromTemplate.js.map +1 -1
  19. package/dist/node/deploySolutionItems.js +161 -168
  20. package/dist/node/deploySolutionItems.js.map +1 -1
  21. package/dist/node/deployer.js +16 -17
  22. package/dist/node/deployer.js.map +1 -1
  23. package/dist/node/deployerUtils.js +18 -23
  24. package/dist/node/deployerUtils.js.map +1 -1
  25. package/dist/node/helpers/post-process.js +16 -18
  26. package/dist/node/helpers/post-process.js.map +1 -1
  27. package/dist/node/helpers/share-templates-to-groups.js +30 -7
  28. package/dist/node/helpers/share-templates-to-groups.js.map +1 -1
  29. package/dist/node/helpers/sortTemplates.js +2 -4
  30. package/dist/node/helpers/sortTemplates.js.map +1 -1
  31. package/dist/node/index.js +1 -1
  32. package/dist/node/module-map.js +9 -9
  33. package/dist/node/module-map.js.map +1 -1
  34. package/dist/umd/deployer.umd.js +1647 -1651
  35. package/dist/umd/deployer.umd.js.map +1 -1
  36. package/dist/umd/deployer.umd.min.js +3 -3
  37. package/dist/umd/deployer.umd.min.js.map +1 -1
  38. package/package.json +33 -33
@@ -20,7 +20,7 @@
20
20
  */
21
21
  import * as common from "@esri/solution-common";
22
22
  import { moduleMap } from "./module-map";
23
- var UNSUPPORTED = null;
23
+ const UNSUPPORTED = null;
24
24
  // ------------------------------------------------------------------------------------------------------------------ //
25
25
  /**
26
26
  * Deploys a set of items defined by templates.
@@ -36,28 +36,26 @@ var UNSUPPORTED = null;
36
36
  * @return A promise that will resolve with the list of information about the created items
37
37
  */
38
38
  export function deploySolutionItems(portalSharingUrl, storageItemId, templates, storageAuthentication, templateDictionary, deployedSolutionId, destinationAuthentication, options) {
39
- return new Promise(function (resolve, reject) {
40
- var _a;
39
+ return new Promise((resolve, reject) => {
41
40
  // Prepare feedback mechanism
42
- var totalEstimatedCost = _estimateDeploymentCost(templates) + 1; // solution items, plus avoid divide by 0
43
- var percentDone = 10; // allow for previous deployment work
44
- var progressPercentStep = (99 - percentDone) / totalEstimatedCost; // leave some % for caller for wrapup
45
- var failedTemplateItemIds = [];
46
- var deployedItemIds = [];
47
- var statusOK = true;
41
+ const totalEstimatedCost = _estimateDeploymentCost(templates) + 1; // solution items, plus avoid divide by 0
42
+ let percentDone = 10; // allow for previous deployment work
43
+ const progressPercentStep = (99 - percentDone) / totalEstimatedCost; // leave some % for caller for wrapup
44
+ const failedTemplateItemIds = [];
45
+ const deployedItemIds = [];
46
+ let statusOK = true;
48
47
  // TODO: move to separate fn
49
- var itemProgressCallback = function (itemId, status, costUsed, createdItemId // supplied when status is EItemProgressStatus.Created or .Finished
50
- ) {
51
- var _a;
48
+ const itemProgressCallback = (itemId, status, costUsed, createdItemId // supplied when status is EItemProgressStatus.Created or .Finished
49
+ ) => {
52
50
  percentDone += progressPercentStep * costUsed;
53
51
  /* istanbul ignore else */
54
52
  if (options.progressCallback) {
55
53
  if (status === common.EItemProgressStatus.Finished) {
56
- var event_1 = {
54
+ const event = {
57
55
  event: common.SItemProgressStatus[status],
58
56
  data: itemId
59
57
  };
60
- options.progressCallback(Math.round(percentDone), options.jobId, event_1);
58
+ options.progressCallback(Math.round(percentDone), options.jobId, event);
61
59
  }
62
60
  else {
63
61
  options.progressCallback(Math.round(percentDone), options.jobId);
@@ -65,7 +63,7 @@ export function deploySolutionItems(portalSharingUrl, storageItemId, templates,
65
63
  }
66
64
  /* istanbul ignore if */
67
65
  if (options.consoleProgress) {
68
- console.log(Date.now(), itemId, (_a = options.jobId) !== null && _a !== void 0 ? _a : "", common.SItemProgressStatus[status], percentDone.toFixed(0) + "%", costUsed, createdItemId ? "==> " + createdItemId : "");
66
+ console.log(Date.now(), itemId, options.jobId ?? "", common.SItemProgressStatus[status], percentDone.toFixed(0) + "%", costUsed, createdItemId ? "==> " + createdItemId : "");
69
67
  }
70
68
  if (status === common.EItemProgressStatus.Created) {
71
69
  deployedItemIds.push(createdItemId);
@@ -85,27 +83,27 @@ export function deploySolutionItems(portalSharingUrl, storageItemId, templates,
85
83
  // Create an ordered graph of the templates so that dependencies are created before the items that need them.
86
84
  // Because cycles are permitted, we also keep track of items that need to be patched later because their
87
85
  // dependencies are necessarily created after they are created.
88
- var _b = common.topologicallySortItems(templates), buildOrder = _b.buildOrder, itemsToBePatched = _b.itemsToBePatched;
86
+ const { buildOrder, itemsToBePatched } = common.topologicallySortItems(templates);
89
87
  // For each item in order from no dependencies to dependent on other items,
90
88
  // * replace template symbols using template dictionary
91
89
  // * create item in destination group
92
90
  // * add created item's id into the template dictionary
93
- var awaitAllItems = [];
94
- var reuseItemsDef = _reuseDeployedItems(templates, (_a = options.enableItemReuse) !== null && _a !== void 0 ? _a : false, templateDictionary, destinationAuthentication);
91
+ const awaitAllItems = [];
92
+ const reuseItemsDef = _reuseDeployedItems(templates, options.enableItemReuse ?? false, templateDictionary, destinationAuthentication);
95
93
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
96
- reuseItemsDef.then(function () {
97
- var useExistingItemsDef = _useExistingItems(templates, common.getProp(templateDictionary, "params.useExisting"), templateDictionary, destinationAuthentication);
94
+ reuseItemsDef.then(() => {
95
+ const useExistingItemsDef = _useExistingItems(templates, common.getProp(templateDictionary, "params.useExisting"), templateDictionary, destinationAuthentication);
98
96
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
99
- useExistingItemsDef.then(function () {
97
+ useExistingItemsDef.then(() => {
100
98
  templates = common.setNamesAndTitles(templates, templateDictionary.solutionItemId);
101
- buildOrder.forEach(function (id) {
99
+ buildOrder.forEach((id) => {
102
100
  // Get the item's template out of the list of templates
103
- var template = common.findTemplateInList(templates, id);
101
+ const template = common.findTemplateInList(templates, id);
104
102
  awaitAllItems.push(_createItemFromTemplateWhenReady(template, common.generateStorageFilePaths(portalSharingUrl, storageItemId, template.resources, options.storageVersion), storageAuthentication, templateDictionary, destinationAuthentication, itemProgressCallback));
105
103
  });
106
104
  // Wait until all items have been created
107
105
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
108
- Promise.all(awaitAllItems).then(function (clonedSolutionItems) {
106
+ Promise.all(awaitAllItems).then((clonedSolutionItems) => {
109
107
  if (failedTemplateItemIds.length === 0) {
110
108
  // Do we have any items to be patched (i.e., they refer to dependencies using the template id rather
111
109
  // than the cloned id because the item had to be created before the dependency)? Flag these items
@@ -115,19 +113,17 @@ export function deploySolutionItems(portalSharingUrl, storageItemId, templates,
115
113
  }
116
114
  else {
117
115
  // Delete created items
118
- var progressOptions = {
116
+ const progressOptions = {
119
117
  consoleProgress: true
120
118
  };
121
119
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
122
120
  common
123
121
  .deleteSolutionByComponents(deployedSolutionId, deployedItemIds, templates, templateDictionary, destinationAuthentication, progressOptions)
124
- .then(function () {
125
- return reject(common.failWithIds(failedTemplateItemIds));
126
- });
122
+ .then(() => reject(common.failWithIds(failedTemplateItemIds)));
127
123
  }
128
124
  });
129
125
  });
130
- }, function (e) {
126
+ }, e => {
131
127
  console.error(e);
132
128
  reject(common.fail(e));
133
129
  });
@@ -141,13 +137,13 @@ export function deploySolutionItems(portalSharingUrl, storageItemId, templates,
141
137
  * @param templates A collection of AGO item templates
142
138
  */
143
139
  export function _flagPatchItemsForPostProcessing(itemsToBePatched, templateDictionary, templates) {
144
- var itemIdsToBePatched = Object.keys(itemsToBePatched);
140
+ let itemIdsToBePatched = Object.keys(itemsToBePatched);
145
141
  /* istanbul ignore else */
146
142
  if (itemIdsToBePatched.length > 0) {
147
143
  // Replace the ids of the items to be patched (which are template ids) with their cloned versions
148
- itemIdsToBePatched = itemIdsToBePatched.map(function (id) { return templateDictionary[id].itemId; });
144
+ itemIdsToBePatched = itemIdsToBePatched.map(id => templateDictionary[id].itemId);
149
145
  // Make sure that the items to be patched are flagged for post processing
150
- templates.forEach(function (item) {
146
+ templates.forEach(item => {
151
147
  /* istanbul ignore else */
152
148
  if (itemIdsToBePatched.includes(item.id)) {
153
149
  item.postProcess = true;
@@ -168,16 +164,16 @@ export function _flagPatchItemsForPostProcessing(itemsToBePatched, templateDicti
168
164
  export function _evaluateSharedViewSources(templates) {
169
165
  // update the templates so we can defer the deployment when more than one view shares the same source
170
166
  // these are not classic dependencies but are in some ways similar
171
- var views = _getViews(templates);
167
+ const views = _getViews(templates);
172
168
  _updateViewTemplates(templates, views);
173
- var viewHash = _getViewHash(views);
174
- var processed = [];
175
- var visited = [];
176
- Object.keys(viewHash).forEach(function (k) {
177
- var _views = viewHash[k];
178
- _views.forEach(function (cv) {
179
- var template = common.findTemplateInList(templates, cv);
180
- var syncViews = common.getProp(template, "properties.syncViews");
169
+ const viewHash = _getViewHash(views);
170
+ let processed = [];
171
+ const visited = [];
172
+ Object.keys(viewHash).forEach(k => {
173
+ const _views = viewHash[k];
174
+ _views.forEach(cv => {
175
+ const template = common.findTemplateInList(templates, cv);
176
+ const syncViews = common.getProp(template, "properties.syncViews");
181
177
  /* istanbul ignore else */
182
178
  if (visited.indexOf(template.itemId) > -1) {
183
179
  processed = processed.concat(syncViews);
@@ -212,9 +208,9 @@ export function _evaluateSharedViewSources(templates) {
212
208
  *
213
209
  */
214
210
  export function _updateViewTemplates(templates, views) {
215
- views.forEach(function (v) {
216
- v.dependencies.forEach(function (id) {
217
- templates = templates.map(function (t) {
211
+ views.forEach(v => {
212
+ v.dependencies.forEach((id) => {
213
+ templates = templates.map(t => {
218
214
  /* istanbul ignore else */
219
215
  if (common.getProp(t, "properties.service.isView") &&
220
216
  t.dependencies.indexOf(id) > -1 &&
@@ -245,9 +241,9 @@ export function _updateViewTemplates(templates, views) {
245
241
  * @protected
246
242
  */
247
243
  export function _getViewHash(views) {
248
- var viewHash = {};
249
- views.forEach(function (v) {
250
- v.dependencies.forEach(function (d) {
244
+ const viewHash = {};
245
+ views.forEach(v => {
246
+ v.dependencies.forEach((d) => {
251
247
  /* istanbul ignore else */
252
248
  if (Object.keys(viewHash).indexOf(d) < 0) {
253
249
  viewHash[d] = [v.id];
@@ -269,7 +265,7 @@ export function _getViewHash(views) {
269
265
  * @protected
270
266
  */
271
267
  export function _getViews(templates) {
272
- return templates.reduce(function (acc, v) {
268
+ return templates.reduce((acc, v) => {
273
269
  /* istanbul ignore else */
274
270
  if (common.getProp(v, "properties.service.isView")) {
275
271
  acc.push({
@@ -293,17 +289,17 @@ export function _getViews(templates) {
293
289
  * @protected
294
290
  */
295
291
  export function _reuseDeployedItems(templates, reuseItems, templateDictionary, authentication) {
296
- return new Promise(function (resolve, reject) {
292
+ return new Promise((resolve, reject) => {
297
293
  if (reuseItems) {
298
- var existingItemsByKeyword = _findExistingItemByKeyword(templates, templateDictionary, authentication);
299
- Promise.all(existingItemsByKeyword).then(function (existingItemsByKeywordResponse) {
300
- var existingItemsByTag = _handleExistingItems(existingItemsByKeywordResponse, templateDictionary, authentication, true);
301
- Promise.all(existingItemsByTag).then(function (existingItemsByTagResponse) {
294
+ const existingItemsByKeyword = _findExistingItemByKeyword(templates, templateDictionary, authentication);
295
+ Promise.all(existingItemsByKeyword).then((existingItemsByKeywordResponse) => {
296
+ const existingItemsByTag = _handleExistingItems(existingItemsByKeywordResponse, templateDictionary, authentication, true);
297
+ Promise.all(existingItemsByTag).then(existingItemsByTagResponse => {
302
298
  _handleExistingItems(existingItemsByTagResponse, templateDictionary, authentication, false);
303
299
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
304
300
  _updateTemplateDictionary(templates, templateDictionary, authentication).then(resolve);
305
- }, function (e) { return reject(common.fail(e)); });
306
- }, function (e) { return reject(common.fail(e)); });
301
+ }, e => reject(common.fail(e)));
302
+ }, e => reject(common.fail(e)));
307
303
  }
308
304
  else {
309
305
  resolve(null);
@@ -331,30 +327,30 @@ export function _reuseDeployedItems(templates, reuseItems, templateDictionary, a
331
327
  * @protected
332
328
  */
333
329
  export function _useExistingItems(templates, useExisting, templateDictionary, authentication) {
334
- return new Promise(function (resolve) {
330
+ return new Promise(resolve => {
335
331
  if (useExisting) {
336
- var itemDefs_1 = [];
337
- var sourceIdHash_1 = {};
338
- var itemIds_1 = [];
339
- Object.keys(templateDictionary.params).forEach(function (k) {
340
- var v = templateDictionary.params[k];
332
+ const itemDefs = [];
333
+ const sourceIdHash = {};
334
+ const itemIds = [];
335
+ Object.keys(templateDictionary.params).forEach(k => {
336
+ const v = templateDictionary.params[k];
341
337
  /* istanbul ignore else */
342
338
  if (v.itemId && /[0-9A-F]{32}/i.test(k)) {
343
339
  _updateTemplateDictionaryById(templateDictionary, k, v.itemId, v);
344
340
  // need to check and set the typeKeyword if it doesn't exist on this service yet
345
341
  // when the user has passed in an itemId that does not come from a previous deployment
346
- itemDefs_1.push(common.getItemBase(v.itemId, authentication));
347
- sourceIdHash_1[v.itemId] = k;
342
+ itemDefs.push(common.getItemBase(v.itemId, authentication));
343
+ sourceIdHash[v.itemId] = k;
348
344
  /* istanbul ignore else */
349
- if (itemIds_1.indexOf(k) < 0) {
350
- itemIds_1.push(k);
345
+ if (itemIds.indexOf(k) < 0) {
346
+ itemIds.push(k);
351
347
  }
352
348
  }
353
349
  });
354
350
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
355
- _setTypekeywordForExisting(itemDefs_1, sourceIdHash_1, authentication).then(function () {
351
+ _setTypekeywordForExisting(itemDefs, sourceIdHash, authentication).then(() => {
356
352
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
357
- _updateTemplateDictionary(itemIds_1.map(function (id) { return common.getTemplateById(templates, id); }), templateDictionary, authentication).then(resolve);
353
+ _updateTemplateDictionary(itemIds.map(id => common.getTemplateById(templates, id)), templateDictionary, authentication).then(resolve);
358
354
  });
359
355
  }
360
356
  else {
@@ -374,32 +370,32 @@ export function _useExistingItems(templates, useExisting, templateDictionary, au
374
370
  * @return a promise to indicate when the requests are complete
375
371
  */
376
372
  export function _setTypekeywordForExisting(itemDefs, sourceIdHash, authentication) {
377
- return new Promise(function (resolve) {
373
+ return new Promise(resolve => {
378
374
  if (itemDefs.length > 0) {
379
- Promise.all(itemDefs).then(function (results) {
380
- var itemUpdateDefs = [];
381
- results.forEach(function (result) {
382
- var sourceId = sourceIdHash[result.id];
375
+ Promise.all(itemDefs).then(results => {
376
+ const itemUpdateDefs = [];
377
+ results.forEach(result => {
378
+ const sourceId = sourceIdHash[result.id];
383
379
  /* istanbul ignore else */
384
380
  if (result && sourceId && result.typeKeywords) {
385
- var sourceKeyword = "source-" + sourceId;
386
- var typeKeywords = result.typeKeywords;
381
+ const sourceKeyword = `source-${sourceId}`;
382
+ const typeKeywords = result.typeKeywords;
387
383
  /* istanbul ignore else */
388
384
  if (typeKeywords.indexOf(sourceKeyword) < 0) {
389
385
  typeKeywords.push(sourceKeyword);
390
- var itemUpdate = { id: result.id, typeKeywords: typeKeywords };
386
+ const itemUpdate = { id: result.id, typeKeywords };
391
387
  itemUpdateDefs.push(common.updateItem(itemUpdate, authentication));
392
388
  }
393
389
  }
394
390
  });
395
391
  // wait for updates to finish before we resolve
396
392
  if (itemUpdateDefs.length > 0) {
397
- Promise.all(itemUpdateDefs).then(resolve, function () { return resolve(undefined); });
393
+ Promise.all(itemUpdateDefs).then(resolve, () => resolve(undefined));
398
394
  }
399
395
  else {
400
396
  resolve(undefined);
401
397
  }
402
- }, function () { return resolve(undefined); });
398
+ }, () => resolve(undefined));
403
399
  }
404
400
  else {
405
401
  resolve(undefined);
@@ -415,18 +411,18 @@ export function _setTypekeywordForExisting(itemDefs, sourceIdHash, authenticatio
415
411
  * @protected
416
412
  */
417
413
  export function _updateTemplateDictionary(templates, templateDictionary, authentication) {
418
- return new Promise(function (resolve) {
419
- var defs = [];
420
- var urls = [];
421
- var types = [];
422
- var ids = [];
423
- templates.forEach(function (t) {
424
- var templateInfo = templateDictionary[t.itemId];
414
+ return new Promise(resolve => {
415
+ const defs = [];
416
+ const urls = [];
417
+ const types = [];
418
+ const ids = [];
419
+ templates.forEach(t => {
420
+ const templateInfo = templateDictionary[t.itemId];
425
421
  /* istanbul ignore else */
426
422
  if (templateInfo && templateInfo.url && templateInfo.itemId) {
427
423
  /* istanbul ignore else */
428
424
  if (t.item.type === "Feature Service") {
429
- var enterpriseIDMapping = common.getProp(templateDictionary, "params." + t.itemId + ".enterpriseIDMapping");
425
+ const enterpriseIDMapping = common.getProp(templateDictionary, `params.${t.itemId}.enterpriseIDMapping`);
430
426
  Object.assign(templateDictionary[t.itemId], common.getLayerSettings(common.getLayersAndTables(t), templateInfo.url, templateInfo.itemId, enterpriseIDMapping));
431
427
  // if the service has veiws keep track of the fields so we can use them to
432
428
  // compare with the view fields
@@ -442,7 +438,7 @@ export function _updateTemplateDictionary(templates, templateDictionary, authent
442
438
  /* istanbul ignore else */
443
439
  if (urls.indexOf(templateInfo.url) < 0) {
444
440
  defs.push(t.item.type === "Feature Service"
445
- ? common.rest_request(templateInfo.url, { authentication: authentication })
441
+ ? common.rest_request(templateInfo.url, { authentication })
446
442
  : common.getItemBase(templateInfo.itemId, authentication));
447
443
  urls.push(templateInfo.url);
448
444
  types.push(t.item.type);
@@ -452,23 +448,23 @@ export function _updateTemplateDictionary(templates, templateDictionary, authent
452
448
  });
453
449
  if (defs.length > 0) {
454
450
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
455
- Promise.all(defs.map(function (p) { return p.catch(function (e) { return e; }); })).then(function (results) {
451
+ Promise.all(defs.map(p => p.catch(e => e))).then(results => {
456
452
  /* istanbul ignore else */
457
453
  if (Array.isArray(results) && results.length > 0) {
458
- var fieldDefs_1 = [];
459
- results.forEach(function (r, i) {
454
+ const fieldDefs = [];
455
+ results.forEach((r, i) => {
460
456
  // a feature service result will contain a serviceItemId if it was successfully fetched
461
457
  if (r.serviceItemId && types[i] === "Feature Service") {
462
- Object.keys(templateDictionary).forEach(function (k) {
463
- var v = templateDictionary[k];
458
+ Object.keys(templateDictionary).forEach(k => {
459
+ const v = templateDictionary[k];
464
460
  /* istanbul ignore else */
465
461
  if (v.itemId && v.itemId === r.serviceItemId) {
466
462
  common.setDefaultSpatialReference(templateDictionary, k, r.spatialReference);
467
463
  // keep the extent values from these responses as well
468
- common.setCreateProp(templateDictionary, k + ".defaultExtent", r.fullExtent || r.initialExtent);
469
- var layerIds = (r.layers || []).map(function (l) { return l.id; });
470
- var tablesIds = (r.tables || []).map(function (t) { return t.id; });
471
- fieldDefs_1.push(common.getExistingLayersAndTables(urls[i], layerIds.concat(tablesIds), authentication));
464
+ common.setCreateProp(templateDictionary, `${k}.defaultExtent`, r.fullExtent || r.initialExtent);
465
+ const layerIds = (r.layers || []).map((l) => l.id);
466
+ const tablesIds = (r.tables || []).map((t) => t.id);
467
+ fieldDefs.push(common.getExistingLayersAndTables(urls[i], layerIds.concat(tablesIds), authentication));
472
468
  }
473
469
  });
474
470
  }
@@ -481,26 +477,26 @@ export function _updateTemplateDictionary(templates, templateDictionary, authent
481
477
  }
482
478
  }
483
479
  });
484
- if (fieldDefs_1.length > 0) {
480
+ if (fieldDefs.length > 0) {
485
481
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
486
- Promise.all(fieldDefs_1).then(function (layerTableResult) {
487
- layerTableResult.forEach(function (l) {
488
- l.forEach(function (ll) {
489
- Object.keys(templateDictionary).forEach(function (k) {
482
+ Promise.all(fieldDefs).then(layerTableResult => {
483
+ layerTableResult.forEach(l => {
484
+ l.forEach((ll) => {
485
+ Object.keys(templateDictionary).forEach(k => {
490
486
  /* istanbul ignore else */
491
487
  if (templateDictionary[k].itemId === ll.serviceItemId) {
492
- var sourceId_1 = "";
493
- Object.keys(templateDictionary).some(function (_k) {
488
+ let sourceId = "";
489
+ Object.keys(templateDictionary).some(_k => {
494
490
  /* istanbul ignore else */
495
491
  if (templateDictionary[_k].itemId === ll.serviceItemId) {
496
- sourceId_1 = _k;
492
+ sourceId = _k;
497
493
  return true;
498
494
  }
499
495
  });
500
- var enterpriseIDMapping_1 = common.getProp(templateDictionary, "params." + sourceId_1 + ".enterpriseIDMapping");
501
- if (enterpriseIDMapping_1) {
502
- Object.keys(enterpriseIDMapping_1).forEach(function (id) {
503
- if (enterpriseIDMapping_1[id].toString() ===
496
+ const enterpriseIDMapping = common.getProp(templateDictionary, `params.${sourceId}.enterpriseIDMapping`);
497
+ if (enterpriseIDMapping) {
498
+ Object.keys(enterpriseIDMapping).forEach(id => {
499
+ if (enterpriseIDMapping[id].toString() ===
504
500
  ll.id.toString()) {
505
501
  _setFields(templateDictionary, k, id, ll.fields);
506
502
  }
@@ -541,7 +537,7 @@ export function _updateTemplateDictionary(templates, templateDictionary, authent
541
537
  * @protected
542
538
  */
543
539
  export function _setFields(templateDictionary, itemId, layerId, fields) {
544
- var layerInfo = common.getProp(templateDictionary, itemId + ".layer" + layerId);
540
+ const layerInfo = common.getProp(templateDictionary, `${itemId}.layer${layerId}`);
545
541
  /* istanbul ignore else */
546
542
  if (layerInfo && fields) {
547
543
  layerInfo.fields = fields;
@@ -562,17 +558,17 @@ export function _setFields(templateDictionary, itemId, layerId, fields) {
562
558
  export function _updateTemplateDictionaryForError(templateDictionary, itemId) {
563
559
  /* istanbul ignore else */
564
560
  if (itemId) {
565
- var removeKey_1 = "";
566
- Object.keys(templateDictionary).some(function (k) {
561
+ let removeKey = "";
562
+ Object.keys(templateDictionary).some(k => {
567
563
  /* istanbul ignore else */
568
564
  if (templateDictionary[k].itemId === itemId) {
569
- removeKey_1 = k;
565
+ removeKey = k;
570
566
  return true;
571
567
  }
572
568
  });
573
569
  /* istanbul ignore else */
574
- if (removeKey_1 !== "") {
575
- delete templateDictionary[removeKey_1];
570
+ if (removeKey !== "") {
571
+ delete templateDictionary[removeKey];
576
572
  }
577
573
  }
578
574
  return templateDictionary;
@@ -589,30 +585,28 @@ export function _updateTemplateDictionaryForError(templateDictionary, itemId) {
589
585
  */
590
586
  export function _handleExistingItems(existingItemsResponse, templateDictionary, authentication, addTagQuery) {
591
587
  // if items are not found by type keyword search by tag
592
- var existingItemsByTag = [Promise.resolve(null)];
588
+ const existingItemsByTag = [Promise.resolve(null)];
593
589
  /* istanbul ignore else */
594
590
  if (existingItemsResponse && Array.isArray(existingItemsResponse)) {
595
- existingItemsResponse.forEach(function (existingItem) {
591
+ existingItemsResponse.forEach(existingItem => {
596
592
  /* istanbul ignore else */
597
- if (Array.isArray(existingItem === null || existingItem === void 0 ? void 0 : existingItem.results)) {
598
- var result = void 0;
599
- var results = existingItem.results;
593
+ if (Array.isArray(existingItem?.results)) {
594
+ let result;
595
+ const results = existingItem.results;
600
596
  if (results.length === 1) {
601
597
  result = results[0];
602
598
  }
603
599
  else if (results.length > 1) {
604
- result = results.reduce(function (a, b) {
605
- return a.created > b.created ? a : b;
606
- });
600
+ result = results.reduce((a, b) => a.created > b.created ? a : b);
607
601
  }
608
602
  else {
609
603
  if (addTagQuery && existingItem.query) {
610
- var tagQuery = existingItem.query.replace("typekeywords", "tags");
604
+ const tagQuery = existingItem.query.replace("typekeywords", "tags");
611
605
  existingItemsByTag.push(_findExistingItem(tagQuery, authentication));
612
606
  }
613
607
  }
614
608
  if (result) {
615
- var sourceId = existingItem.query
609
+ const sourceId = existingItem.query
616
610
  ? existingItem.query.match(/[0-9A-F]{32}/i)[0]
617
611
  : existingItem.sourceId;
618
612
  /* istanbul ignore else */
@@ -628,7 +622,7 @@ export function _handleExistingItems(existingItemsResponse, templateDictionary,
628
622
  export function _updateTemplateDictionaryById(templateDictionary, sourceId, itemId, v) {
629
623
  templateDictionary[sourceId] = Object.assign(templateDictionary[sourceId] || {}, {
630
624
  def: Promise.resolve(common.generateEmptyCreationResponse(v.type, itemId)),
631
- itemId: itemId,
625
+ itemId,
632
626
  name: v.name,
633
627
  title: v.title,
634
628
  url: v.url
@@ -643,17 +637,16 @@ export function _updateTemplateDictionaryById(templateDictionary, sourceId, item
643
637
  * @protected
644
638
  */
645
639
  export function _findExistingItemByKeyword(templates, templateDictionary, authentication) {
646
- var existingItemsDefs = [];
647
- templates.forEach(function (template) {
648
- var _a;
640
+ const existingItemsDefs = [];
641
+ templates.forEach(template => {
649
642
  if (template.item.type === "Group") {
650
- var userGroups = (_a = templateDictionary.user) === null || _a === void 0 ? void 0 : _a.groups;
643
+ const userGroups = templateDictionary.user?.groups;
651
644
  /* istanbul ignore else */
652
645
  if (Array.isArray(userGroups)) {
653
646
  existingItemsDefs.push(Promise.resolve({
654
647
  results: userGroups
655
- .filter(function (g) { return g.tags.indexOf("source-" + template.itemId) > -1; })
656
- .map(function (g) {
648
+ .filter(g => g.tags.indexOf(`source-${template.itemId}`) > -1)
649
+ .map(g => {
657
650
  g.type = "Group";
658
651
  return g;
659
652
  }),
@@ -662,7 +655,7 @@ export function _findExistingItemByKeyword(templates, templateDictionary, authen
662
655
  }
663
656
  }
664
657
  else {
665
- existingItemsDefs.push(_findExistingItem("typekeywords:source-" + template.itemId + " type:" + template.item.type + " owner:" + templateDictionary.user.username, authentication));
658
+ existingItemsDefs.push(_findExistingItem(`typekeywords:source-${template.itemId} type:${template.item.type} owner:${templateDictionary.user.username}`, authentication));
666
659
  }
667
660
  });
668
661
  return existingItemsDefs;
@@ -676,7 +669,7 @@ export function _findExistingItemByKeyword(templates, templateDictionary, authen
676
669
  * @protected
677
670
  */
678
671
  export function _findExistingItem(query, authentication) {
679
- var searchOptions = {
672
+ const searchOptions = {
680
673
  q: query,
681
674
  authentication: authentication,
682
675
  pagingParam: { start: 1, num: 100 }
@@ -702,16 +695,16 @@ export function _createItemFromTemplateWhenReady(template, resourceFilePaths, st
702
695
  // or if we have a basic entry without the deferred request for its creation, add it
703
696
  if (!templateDictionary.hasOwnProperty(template.itemId) ||
704
697
  !common.getProp(templateDictionary[template.itemId], "def")) {
705
- var createResponse_1;
706
- var statusCode_1 = common.EItemProgressStatus.Unknown;
707
- var itemHandler_1;
698
+ let createResponse;
699
+ let statusCode = common.EItemProgressStatus.Unknown;
700
+ let itemHandler;
708
701
  templateDictionary[template.itemId] =
709
702
  templateDictionary[template.itemId] || {};
710
703
  // Save the deferred for the use of items that depend on this item being created first
711
- templateDictionary[template.itemId].def = new Promise(function (resolve) {
704
+ templateDictionary[template.itemId].def = new Promise(resolve => {
712
705
  // Wait until all of the item's dependencies are deployed
713
- var _awaitDependencies = template.dependencies.reduce(function (acc, id) {
714
- var def = common.getProp(templateDictionary, id + ".def");
706
+ const _awaitDependencies = template.dependencies.reduce((acc, id) => {
707
+ const def = common.getProp(templateDictionary, `${id}.def`);
715
708
  // can't use maybePush as that clones the object, which does not work for Promises
716
709
  /* istanbul ignore else */
717
710
  if (def) {
@@ -719,10 +712,10 @@ export function _createItemFromTemplateWhenReady(template, resourceFilePaths, st
719
712
  }
720
713
  return acc;
721
714
  }, []);
722
- var syncViews = common.getProp(template, "properties.syncViews");
723
- var awaitDependencies = syncViews && syncViews.length > 0
724
- ? syncViews.reduce(function (acc, v) {
725
- var def = common.getProp(templateDictionary, v + ".def");
715
+ const syncViews = common.getProp(template, "properties.syncViews");
716
+ const awaitDependencies = syncViews && syncViews.length > 0
717
+ ? syncViews.reduce((acc, v) => {
718
+ const def = common.getProp(templateDictionary, `${v}.def`);
726
719
  /* istanbul ignore else */
727
720
  if (def) {
728
721
  acc.push(def);
@@ -731,55 +724,55 @@ export function _createItemFromTemplateWhenReady(template, resourceFilePaths, st
731
724
  }, _awaitDependencies)
732
725
  : _awaitDependencies;
733
726
  Promise.all(awaitDependencies)
734
- .then(function () {
727
+ .then(() => {
735
728
  // Find the conversion handler for this item type
736
- var templateType = template.type;
737
- itemHandler_1 = moduleMap[templateType];
738
- if (!itemHandler_1 || itemHandler_1 === UNSUPPORTED) {
739
- if (itemHandler_1 === UNSUPPORTED) {
740
- statusCode_1 = common.EItemProgressStatus.Ignored;
729
+ const templateType = template.type;
730
+ itemHandler = moduleMap[templateType];
731
+ if (!itemHandler || itemHandler === UNSUPPORTED) {
732
+ if (itemHandler === UNSUPPORTED) {
733
+ statusCode = common.EItemProgressStatus.Ignored;
741
734
  throw new Error();
742
735
  }
743
736
  else {
744
- statusCode_1 = common.EItemProgressStatus.Failed;
737
+ statusCode = common.EItemProgressStatus.Failed;
745
738
  throw new Error();
746
739
  }
747
740
  }
748
741
  // Get the item's thumbnail
749
742
  return common.getThumbnailFromStorageItem(storageAuthentication, resourceFilePaths);
750
743
  })
751
- .then(function (thumbnail) {
744
+ .then(thumbnail => {
752
745
  template.item.thumbnail = thumbnail;
753
746
  // Delegate the creation of the item to the handler
754
747
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
755
- return itemHandler_1.createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback);
748
+ return itemHandler.createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback);
756
749
  })
757
- .then(function (response) {
750
+ .then((response) => {
758
751
  if (response.id === "") {
759
- statusCode_1 = common.EItemProgressStatus.Failed;
752
+ statusCode = common.EItemProgressStatus.Failed;
760
753
  throw new Error("handled"); // fails to create item
761
754
  }
762
755
  /* istanbul ignore else */
763
- createResponse_1 = response;
764
- if (createResponse_1.item.item.url) {
765
- common.setCreateProp(templateDictionary, template.itemId + ".url", createResponse_1.item.item.url);
756
+ createResponse = response;
757
+ if (createResponse.item.item.url) {
758
+ common.setCreateProp(templateDictionary, template.itemId + ".url", createResponse.item.item.url);
766
759
  }
767
760
  if (resourceFilePaths.length > 0) {
768
761
  // Copy resources, metadata, form
769
- return common.copyFilesFromStorageItem(storageAuthentication, resourceFilePaths, templateDictionary.folderId, createResponse_1.id, destinationAuthentication, createResponse_1.item);
762
+ return common.copyFilesFromStorageItem(storageAuthentication, resourceFilePaths, templateDictionary.folderId, createResponse.id, destinationAuthentication, createResponse.item);
770
763
  }
771
764
  else {
772
765
  return Promise.resolve(null);
773
766
  }
774
767
  })
775
- .then(function () {
776
- resolve(createResponse_1);
768
+ .then(() => {
769
+ resolve(createResponse);
777
770
  })
778
- .catch(function (error) {
771
+ .catch(error => {
779
772
  if (!error || error.message !== "handled") {
780
- itemProgressCallback(template.itemId, statusCode_1 === common.EItemProgressStatus.Unknown
773
+ itemProgressCallback(template.itemId, statusCode === common.EItemProgressStatus.Unknown
781
774
  ? common.EItemProgressStatus.Failed
782
- : statusCode_1, 0);
775
+ : statusCode, 0);
783
776
  }
784
777
  // Item type not supported or fails to get item dependencies
785
778
  resolve(common.generateEmptyCreationResponse(template.type));
@@ -796,15 +789,15 @@ export function _createItemFromTemplateWhenReady(template, resourceFilePaths, st
796
789
  * @protected
797
790
  */
798
791
  export function _estimateDeploymentCost(templates) {
799
- return templates.reduce(function (accumulatedEstimatedCost, template) {
792
+ return templates.reduce((accumulatedEstimatedCost, template) => {
800
793
  return (accumulatedEstimatedCost + (template.estimatedDeploymentCostFactor || 1));
801
794
  }, 0);
802
795
  }
803
796
  // TODO: Return a Promise vs array of promises
804
797
  export function _getGroupUpdates(template, authentication, templateDictionary) {
805
- var groups = template.groups || [];
806
- return groups.map(function (sourceGroupId) {
807
- return common.shareItem(templateDictionary[sourceGroupId].itemId, template.itemId, authentication);
798
+ const groups = template.groups || [];
799
+ return groups.map((sourceGroupId) => {
800
+ return common.shareItem(templateDictionary[sourceGroupId].itemId, template.itemId, authentication, common.isTrackingViewTemplate(template) ? templateDictionary.locationTracking.owner : undefined);
808
801
  });
809
802
  }
810
803
  //# sourceMappingURL=deploySolutionItems.js.map