@esri/solution-hub-types 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/esm/helpers/_post-process-page.d.ts +2 -2
  2. package/dist/esm/helpers/_post-process-page.js +4 -2
  3. package/dist/esm/helpers/_post-process-page.js.map +1 -1
  4. package/dist/esm/helpers/_post-process-site.d.ts +2 -2
  5. package/dist/esm/helpers/_post-process-site.js +11 -25
  6. package/dist/esm/helpers/_post-process-site.js.map +1 -1
  7. package/dist/esm/helpers/_update-site-pages.d.ts +2 -2
  8. package/dist/esm/helpers/_update-site-pages.js +5 -5
  9. package/dist/esm/helpers/_update-site-pages.js.map +1 -1
  10. package/dist/esm/helpers/move-model-to-folder.js +6 -6
  11. package/dist/esm/helpers/move-model-to-folder.js.map +1 -1
  12. package/dist/esm/helpers/replace-item-ids.js +5 -5
  13. package/dist/esm/helpers/replace-item-ids.js.map +1 -1
  14. package/dist/esm/hub-page-processor.d.ts +3 -2
  15. package/dist/esm/hub-page-processor.js +44 -34
  16. package/dist/esm/hub-page-processor.js.map +1 -1
  17. package/dist/esm/hub-site-processor.d.ts +10 -9
  18. package/dist/esm/hub-site-processor.js +72 -61
  19. package/dist/esm/hub-site-processor.js.map +1 -1
  20. package/dist/node/helpers/_post-process-page.d.ts +2 -2
  21. package/dist/node/helpers/_post-process-page.js +6 -4
  22. package/dist/node/helpers/_post-process-page.js.map +1 -1
  23. package/dist/node/helpers/_post-process-site.d.ts +2 -2
  24. package/dist/node/helpers/_post-process-site.js +12 -26
  25. package/dist/node/helpers/_post-process-site.js.map +1 -1
  26. package/dist/node/helpers/_update-site-pages.d.ts +2 -2
  27. package/dist/node/helpers/_update-site-pages.js +7 -7
  28. package/dist/node/helpers/_update-site-pages.js.map +1 -1
  29. package/dist/node/helpers/move-model-to-folder.js +8 -8
  30. package/dist/node/helpers/move-model-to-folder.js.map +1 -1
  31. package/dist/node/helpers/replace-item-ids.js +6 -6
  32. package/dist/node/helpers/replace-item-ids.js.map +1 -1
  33. package/dist/node/hub-page-processor.d.ts +3 -2
  34. package/dist/node/hub-page-processor.js +51 -41
  35. package/dist/node/hub-page-processor.js.map +1 -1
  36. package/dist/node/hub-site-processor.d.ts +10 -9
  37. package/dist/node/hub-site-processor.js +81 -70
  38. package/dist/node/hub-site-processor.js.map +1 -1
  39. package/dist/node/index.js +2 -2
  40. package/dist/node/index.js.map +1 -1
  41. package/dist/umd/helpers/_post-process-page.d.ts +2 -2
  42. package/dist/umd/helpers/_post-process-site.d.ts +2 -2
  43. package/dist/umd/helpers/_update-site-pages.d.ts +2 -2
  44. package/dist/umd/hub-page-processor.d.ts +3 -2
  45. package/dist/umd/hub-site-processor.d.ts +10 -9
  46. package/dist/umd/hub-types.umd.js +621 -620
  47. package/dist/umd/hub-types.umd.js.map +1 -1
  48. package/dist/umd/hub-types.umd.min.js +3 -3
  49. package/dist/umd/hub-types.umd.min.js.map +1 -1
  50. package/package.json +25 -25
@@ -1,7 +1,7 @@
1
1
  /* @preserve
2
- * @esri/solution-hub-types - v1.1.2 - Apache-2.0
2
+ * @esri/solution-hub-types - v1.2.0 - Apache-2.0
3
3
  * Copyright (c) 2018-2021 Esri, Inc.
4
- * Mon Aug 30 2021 23:58:59 GMT-0700 (Pacific Daylight Time)
4
+ * Thu Dec 09 2021 16:02:36 GMT-0800 (Pacific Standard Time)
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -16,634 +16,635 @@
16
16
  * limitations under the License.
17
17
  */
18
18
  (function (global, factory) {
19
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/solution-common'), require('@esri/arcgis-rest-portal'), require('@esri/hub-common'), require('@esri/hub-sites')) :
20
- typeof define === 'function' && define.amd ? define(['exports', '@esri/solution-common', '@esri/arcgis-rest-portal', '@esri/hub-common', '@esri/hub-sites'], factory) :
21
- (global = global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution, global.arcgisRest, global.arcgisHub, global.arcgisHub));
22
- }(this, (function (exports, solutionCommon, arcgisRestPortal, hubCommon, hubSites) { 'use strict';
19
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/solution-common'), require('@esri/arcgis-rest-portal'), require('@esri/hub-common'), require('@esri/hub-sites')) :
20
+ typeof define === 'function' && define.amd ? define(['exports', '@esri/solution-common', '@esri/arcgis-rest-portal', '@esri/hub-common', '@esri/hub-sites'], factory) :
21
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution, global.arcgisRest, global.arcgisHub, global.arcgisHub));
22
+ })(this, (function (exports, solutionCommon, arcgisRestPortal, hubCommon, hubSites) { 'use strict';
23
23
 
24
- /*! *****************************************************************************
25
- Copyright (c) Microsoft Corporation. All rights reserved.
26
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
27
- this file except in compliance with the License. You may obtain a copy of the
28
- License at http://www.apache.org/licenses/LICENSE-2.0
29
-
30
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
31
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
32
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
33
- MERCHANTABLITY OR NON-INFRINGEMENT.
34
-
35
- See the Apache Version 2.0 License for specific language governing permissions
36
- and limitations under the License.
37
- ***************************************************************************** */
38
-
39
- var __assign = function() {
40
- __assign = Object.assign || function __assign(t) {
41
- for (var s, i = 1, n = arguments.length; i < n; i++) {
42
- s = arguments[i];
43
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
44
- }
45
- return t;
46
- };
47
- return __assign.apply(this, arguments);
48
- };
49
-
50
- function __read(o, n) {
51
- var m = typeof Symbol === "function" && o[Symbol.iterator];
52
- if (!m) return o;
53
- var i = m.call(o), r, ar = [], e;
54
- try {
55
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
56
- }
57
- catch (error) { e = { error: error }; }
58
- finally {
59
- try {
60
- if (r && !r.done && (m = i["return"])) m.call(i);
61
- }
62
- finally { if (e) throw e.error; }
63
- }
64
- return ar;
65
- }
24
+ /** @license
25
+ * Copyright 2020 Esri
26
+ *
27
+ * Licensed under the Apache License, Version 2.0 (the "License");
28
+ * you may not use this file except in compliance with the License.
29
+ * You may obtain a copy of the License at
30
+ *
31
+ * http://www.apache.org/licenses/LICENSE-2.0
32
+ *
33
+ * Unless required by applicable law or agreed to in writing, software
34
+ * distributed under the License is distributed on an "AS IS" BASIS,
35
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36
+ * See the License for the specific language governing permissions and
37
+ * limitations under the License.
38
+ */
39
+ function _postProcessPage(pageModel, itemInfos, templateDictionary, hubRequestOptions) {
40
+ // re-interpolate the siteModel using the itemInfos; no patches supplied
41
+ pageModel = hubCommon.interpolate(pageModel, templateDictionary, {});
42
+ return hubSites.updatePage(pageModel, {
43
+ ...hubRequestOptions,
44
+ allowList: []
45
+ }).then(() => {
46
+ return true;
47
+ });
48
+ }
66
49
 
67
- function _postProcessPage(pageModel, itemInfos, templateDictionary, hubRequestOptions) {
68
- // re-interpolate the siteModel using the itemInfos; no patches supplied
69
- pageModel = hubCommon.interpolate(pageModel, templateDictionary, {});
70
- return hubSites.updatePage(pageModel, __assign(__assign({}, hubRequestOptions), { allowList: [] })).then(function () {
71
- return true;
72
- });
73
- }
50
+ /** @license
51
+ * Copyright 2020 Esri
52
+ *
53
+ * Licensed under the Apache License, Version 2.0 (the "License");
54
+ * you may not use this file except in compliance with the License.
55
+ * You may obtain a copy of the License at
56
+ *
57
+ * http://www.apache.org/licenses/LICENSE-2.0
58
+ *
59
+ * Unless required by applicable law or agreed to in writing, software
60
+ * distributed under the License is distributed on an "AS IS" BASIS,
61
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
62
+ * See the License for the specific language governing permissions and
63
+ * limitations under the License.
64
+ */
65
+ function replaceItemIds(template) {
66
+ const clone = hubCommon.cloneObject(template);
67
+ const deps = template.dependencies || [];
68
+ // iterate the dependencies
69
+ deps.forEach(depId => {
70
+ const re = new RegExp(depId, "g");
71
+ const replacement = `{{${depId}.itemId}}`;
72
+ // we have to do this property-by-property or we would replace the `itemId` prop itself
73
+ clone.item = hubCommon.deepStringReplace(clone.item, re, replacement);
74
+ clone.data = hubCommon.deepStringReplace(clone.data, re, replacement);
75
+ if (template.properties) {
76
+ clone.properties = hubCommon.deepStringReplace(clone.properties, re, replacement);
77
+ }
78
+ });
79
+ return clone;
80
+ }
74
81
 
75
- /** @license
76
- * Copyright 2020 Esri
77
- *
78
- * Licensed under the Apache License, Version 2.0 (the "License");
79
- * you may not use this file except in compliance with the License.
80
- * You may obtain a copy of the License at
81
- *
82
- * http://www.apache.org/licenses/LICENSE-2.0
83
- *
84
- * Unless required by applicable law or agreed to in writing, software
85
- * distributed under the License is distributed on an "AS IS" BASIS,
86
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
87
- * See the License for the specific language governing permissions and
88
- * limitations under the License.
89
- */
90
- function replaceItemIds(template) {
91
- var clone = hubCommon.cloneObject(template);
92
- var deps = template.dependencies || [];
93
- // iterate the dependencies
94
- deps.forEach(function (depId) {
95
- var re = new RegExp(depId, "g");
96
- var replacement = "{{" + depId + ".itemId}}";
97
- // we have to do this property-by-property or we would replace the `itemId` prop itself
98
- clone.item = hubCommon.deepStringReplace(clone.item, re, replacement);
99
- clone.data = hubCommon.deepStringReplace(clone.data, re, replacement);
100
- if (template.properties) {
101
- clone.properties = hubCommon.deepStringReplace(clone.properties, re, replacement);
102
- }
103
- });
104
- return clone;
105
- }
82
+ /** @license
83
+ * Copyright 2018 Esri
84
+ *
85
+ * Licensed under the Apache License, Version 2.0 (the "License");
86
+ * you may not use this file except in compliance with the License.
87
+ * You may obtain a copy of the License at
88
+ *
89
+ * http://www.apache.org/licenses/LICENSE-2.0
90
+ *
91
+ * Unless required by applicable law or agreed to in writing, software
92
+ * distributed under the License is distributed on an "AS IS" BASIS,
93
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
94
+ * See the License for the specific language governing permissions and
95
+ * limitations under the License.
96
+ */
97
+ /**
98
+ * Move the created site item, and optionally the Initiative, into
99
+ * the solution folder
100
+ *
101
+ * @param siteModel
102
+ * @param folderId
103
+ * @param authentication
104
+ */
105
+ function moveModelToFolder(siteModel, folderId, authentication) {
106
+ // Fail-Safe the move call as it's not critical if it fails
107
+ const failSafeMove = hubCommon.failSafe(arcgisRestPortal.moveItem, { success: true });
108
+ const movePromises = [
109
+ failSafeMove({
110
+ itemId: siteModel.item.id,
111
+ folderId,
112
+ authentication
113
+ })
114
+ ];
115
+ // if an initiative was created...
116
+ if (hubCommon.getProp(siteModel, "item.properties.parentInitiativeId")) {
117
+ movePromises.push(failSafeMove({
118
+ itemId: siteModel.item.properties.parentInitiativeId,
119
+ folderId,
120
+ authentication
121
+ }));
122
+ }
123
+ return Promise.all(movePromises);
124
+ }
106
125
 
107
- /** @license
108
- * Copyright 2018 Esri
109
- *
110
- * Licensed under the Apache License, Version 2.0 (the "License");
111
- * you may not use this file except in compliance with the License.
112
- * You may obtain a copy of the License at
113
- *
114
- * http://www.apache.org/licenses/LICENSE-2.0
115
- *
116
- * Unless required by applicable law or agreed to in writing, software
117
- * distributed under the License is distributed on an "AS IS" BASIS,
118
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
119
- * See the License for the specific language governing permissions and
120
- * limitations under the License.
121
- */
122
- /**
123
- * Move the created site item, and optionally the Initiative, into
124
- * the solution folder
125
- *
126
- * @param siteModel
127
- * @param folderId
128
- * @param authentication
129
- */
130
- function moveModelToFolder(siteModel, folderId, authentication) {
131
- // Fail-Safe the move call as it's not critical if it fails
132
- var failSafeMove = hubCommon.failSafe(arcgisRestPortal.moveItem, { success: true });
133
- var movePromises = [
134
- failSafeMove({
135
- itemId: siteModel.item.id,
136
- folderId: folderId,
137
- authentication: authentication
138
- })
139
- ];
140
- // if an initiative was created...
141
- if (hubCommon.getProp(siteModel, "item.properties.parentInitiativeId")) {
142
- movePromises.push(failSafeMove({
143
- itemId: siteModel.item.properties.parentInitiativeId,
144
- folderId: folderId,
145
- authentication: authentication
146
- }));
147
- }
148
- return Promise.all(movePromises);
149
- }
126
+ /** @license
127
+ * Copyright 2018 Esri
128
+ *
129
+ * Licensed under the Apache License, Version 2.0 (the "License");
130
+ * you may not use this file except in compliance with the License.
131
+ * You may obtain a copy of the License at
132
+ *
133
+ * http://www.apache.org/licenses/LICENSE-2.0
134
+ *
135
+ * Unless required by applicable law or agreed to in writing, software
136
+ * distributed under the License is distributed on an "AS IS" BASIS,
137
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138
+ * See the License for the specific language governing permissions and
139
+ * limitations under the License.
140
+ */
141
+ /**
142
+ * Converts a Hub Page item into a template.
143
+ *
144
+ * @param solutionItemId The solution to contain the template
145
+ * @param itemInfo Info about the item
146
+ * @param destAuthentication Credentials for requests to the destination organization
147
+ * @param srcAuthentication Credentials for requests to source items (placeholder--not used)
148
+ * @return A promise that will resolve when the template has been created
149
+ */
150
+ function convertItemToTemplate$1(solutionItemId, itemInfo, destAuthentication, srcAuthentication = null // eslint-disable-line @typescript-eslint/no-unused-vars
151
+ ) {
152
+ let created = 0;
153
+ let modified = 0;
154
+ // get the page model and hubRequestOptions
155
+ return Promise.all([
156
+ hubCommon.getModel(itemInfo.id, { authentication: destAuthentication }),
157
+ solutionCommon.createHubRequestOptions(destAuthentication)
158
+ ])
159
+ .then(([pageModel, ro]) => {
160
+ // We need to save these properties in order to restore them after hub.js deletes them
161
+ created = pageModel.item.created;
162
+ modified = pageModel.item.modified;
163
+ return hubSites.convertPageToTemplate(pageModel, ro);
164
+ })
165
+ .then(tmpl => {
166
+ // add in some stuff Hub.js does not yet add
167
+ tmpl.item.created = created;
168
+ tmpl.item.modified = modified;
169
+ tmpl.item.typeKeywords = hubCommon.without(tmpl.item.typeKeywords, "doNotDelete");
170
+ tmpl.groups = [];
171
+ tmpl.estimatedDeploymentCostFactor = 2;
172
+ tmpl.resources = [];
173
+ if (!hubCommon.getProp(tmpl, "properties")) {
174
+ tmpl.properties = {};
175
+ }
176
+ // swap out dependency id's to {{<depid>.itemId}}
177
+ // so it will be re-interpolated
178
+ tmpl = replaceItemIds(tmpl);
179
+ // and return it
180
+ return tmpl;
181
+ });
182
+ }
183
+ /**
184
+ * Handle deployment of Page item templates
185
+ *
186
+ * @export
187
+ * @param {IItemTemplate} template
188
+ * @param {*} templateDictionary
189
+ * @param {UserSession} destinationAuthentication
190
+ * @param {IItemProgressCallback} itemProgressCallback
191
+ * @returns {Promise<ICreateItemFromTemplateResponse>}
192
+ */
193
+ function createItemFromTemplate$1(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
194
+ // let the progress system know we've started...
195
+ const startStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Started, 0);
196
+ // and if it returned false, just resolve out
197
+ if (!startStatus) {
198
+ return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
199
+ }
200
+ // TODO: Reassess with resource unification
201
+ if (template.assets && template.resources) {
202
+ delete template.assets;
203
+ }
204
+ // solutionItemExtent is in geographic, but it's a string, and we want/need a bbox
205
+ // and Hub templates expect it in organization.defaultExtentBBox
206
+ if (templateDictionary.solutionItemExtent) {
207
+ const parts = templateDictionary.solutionItemExtent.split(",");
208
+ templateDictionary.organization.defaultExtentBBox = [
209
+ [parts[0], parts[1]],
210
+ [parts[2], parts[3]]
211
+ ];
212
+ }
213
+ // TODO: Determine if we need any transforms in this new env
214
+ const transforms = {};
215
+ // create an object to hold the created site through
216
+ // subsequent promise calls
217
+ let pageModel;
218
+ let hubRo;
219
+ const thumbnail = template.item.thumbnail; // createPageModelFromTemplate trashes thumbnail
220
+ return solutionCommon.createHubRequestOptions(destinationAuthentication, templateDictionary)
221
+ .then(ro => {
222
+ hubRo = ro;
223
+ return hubSites.createPageModelFromTemplate(template, templateDictionary, transforms, hubRo);
224
+ })
225
+ .then((interpolated) => {
226
+ // --------------------------------------------
227
+ // TODO: Update hub.js to take an IModel in createPage
228
+ // then remove this silliness
229
+ const modelTmpl = interpolated;
230
+ const options = {
231
+ assets: modelTmpl.assets || []
232
+ };
233
+ // --------------------------------------------
234
+ return hubSites.createPage(modelTmpl, options, hubRo);
235
+ })
236
+ .then(page => {
237
+ pageModel = page;
238
+ // Move the site and initiative to the solution folder
239
+ // this is essentially fire and forget. We fail-safe the actual moveItem
240
+ // call since it's not critical to the outcome
241
+ return moveModelToFolder(page, templateDictionary.folderId, destinationAuthentication);
242
+ })
243
+ .then(() => {
244
+ // Fix the thumbnail
245
+ const updateOptions = {
246
+ item: {
247
+ id: pageModel.item.id
248
+ },
249
+ params: {
250
+ // Pass thumbnail in via params because item property is serialized, which discards a blob
251
+ thumbnail
252
+ },
253
+ authentication: destinationAuthentication
254
+ };
255
+ return arcgisRestPortal.updateItem(updateOptions);
256
+ })
257
+ .then(() => {
258
+ // Update the template dictionary
259
+ // TODO: This should be done in whatever recieves
260
+ // the outcome of this promise chain
261
+ templateDictionary[template.itemId] = {
262
+ itemId: pageModel.item.id
263
+ };
264
+ // call the progress callback, which also mutates templateDictionary
265
+ const finalStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor || 2, pageModel.item.id);
266
+ if (!finalStatus) {
267
+ // clean up the site we just created
268
+ const failSafeRemove = hubCommon.failSafe(hubSites.removePage, { success: true });
269
+ return failSafeRemove(pageModel, hubRo).then(() => {
270
+ return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
271
+ });
272
+ }
273
+ else {
274
+ // finally, return ICreateItemFromTemplateResponse
275
+ const response = {
276
+ item: {
277
+ ...template,
278
+ ...pageModel
279
+ },
280
+ id: pageModel.item.id,
281
+ type: template.type,
282
+ postProcess: true
283
+ };
284
+ response.item.itemId = pageModel.item.id;
285
+ return response;
286
+ }
287
+ })
288
+ .catch(ex => {
289
+ itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Failed, 0);
290
+ throw ex;
291
+ });
292
+ }
293
+ /**
294
+ * Post-Process a Page
295
+ * Re-interpolate the page item + data w/ the full template dictionary hash
296
+ *
297
+ * @param id
298
+ * @param type
299
+ * @param itemInfos
300
+ * @param template
301
+ * @param templates
302
+ * @param templateDictionary
303
+ * @param authentication
304
+ */
305
+ function postProcess$1(id, type, itemInfos, template, templates, templateDictionary, authentication) {
306
+ // create the requestOptions
307
+ let hubRo;
308
+ // get hubRequestOptions
309
+ return solutionCommon.createHubRequestOptions(authentication)
310
+ .then(ro => {
311
+ hubRo = ro;
312
+ // get the site model
313
+ return hubCommon.getModel(id, { authentication });
314
+ })
315
+ .then(pageModel => {
316
+ // post process the page
317
+ return _postProcessPage(pageModel, itemInfos, templateDictionary, hubRo);
318
+ });
319
+ }
320
+ /**
321
+ * Check of an item type is a Page
322
+ * Hub Page is for ArcGIS Online
323
+ * Site Page is for ArcGIS Enterprise
324
+ *
325
+ * @param itemType
326
+ */
327
+ function isAPage(itemType) {
328
+ let result = false;
329
+ if (itemType === "Hub Page" || itemType === "Site Page") {
330
+ result = true;
331
+ }
332
+ return result;
333
+ }
150
334
 
151
- /** @license
152
- * Copyright 2018 Esri
153
- *
154
- * Licensed under the Apache License, Version 2.0 (the "License");
155
- * you may not use this file except in compliance with the License.
156
- * You may obtain a copy of the License at
157
- *
158
- * http://www.apache.org/licenses/LICENSE-2.0
159
- *
160
- * Unless required by applicable law or agreed to in writing, software
161
- * distributed under the License is distributed on an "AS IS" BASIS,
162
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163
- * See the License for the specific language governing permissions and
164
- * limitations under the License.
165
- */
166
- /**
167
- * Converts a Hub Page item into a template.
168
- *
169
- * @param solutionItemId The solution to contain the template
170
- * @param itemInfo Info about the item
171
- * @param authentication Credentials for working with AGO
172
- * @return A promise that will resolve when the template has been created
173
- */
174
- function convertItemToTemplate(solutionItemId, itemInfo, authentication) {
175
- // get the page model and hubRequestOptions
176
- return Promise.all([
177
- hubCommon.getModel(itemInfo.id, { authentication: authentication }),
178
- solutionCommon.createHubRequestOptions(authentication)
179
- ])
180
- .then(function (_a) {
181
- var _b = __read(_a, 2), pageModel = _b[0], ro = _b[1];
182
- return hubSites.convertPageToTemplate(pageModel, ro);
183
- })
184
- .then(function (tmpl) {
185
- // add in some stuff Hub.js does not yet add
186
- tmpl.item.typeKeywords = hubCommon.without(tmpl.item.typeKeywords, "doNotDelete");
187
- tmpl.groups = [];
188
- tmpl.estimatedDeploymentCostFactor = 2;
189
- tmpl.resources = [];
190
- if (!hubCommon.getProp(tmpl, "properties")) {
191
- tmpl.properties = {};
192
- }
193
- // swap out dependency id's to {{<depid>.itemId}}
194
- // so it will be re-interpolated
195
- tmpl = replaceItemIds(tmpl);
196
- // and return it
197
- return tmpl;
198
- });
199
- }
200
- /**
201
- * Handle deployment of Page item templates
202
- *
203
- * @export
204
- * @param {IItemTemplate} template
205
- * @param {*} templateDictionary
206
- * @param {UserSession} destinationAuthentication
207
- * @param {IItemProgressCallback} itemProgressCallback
208
- * @returns {Promise<ICreateItemFromTemplateResponse>}
209
- */
210
- function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
211
- // let the progress system know we've started...
212
- var startStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Started, 0);
213
- // and if it returned false, just resolve out
214
- if (!startStatus) {
215
- return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
216
- }
217
- // TODO: Reassess with resource unification
218
- if (template.assets && template.resources) {
219
- delete template.assets;
220
- }
221
- // solutionItemExtent is in geographic, but it's a string, and we want/need a bbox
222
- // and Hub templates expect it in organization.defaultExtentBBox
223
- if (templateDictionary.solutionItemExtent) {
224
- var parts = templateDictionary.solutionItemExtent.split(",");
225
- templateDictionary.organization.defaultExtentBBox = [
226
- [parts[0], parts[1]],
227
- [parts[2], parts[3]]
228
- ];
229
- }
230
- // TODO: Determine if we need any transforms in this new env
231
- var transforms = {};
232
- // create an object to hold the created site through
233
- // subsequent promise calls
234
- var pageModel;
235
- var hubRo;
236
- var thumbnail = template.item.thumbnail; // createPageModelFromTemplate trashes thumbnail
237
- return solutionCommon.createHubRequestOptions(destinationAuthentication, templateDictionary)
238
- .then(function (ro) {
239
- hubRo = ro;
240
- return hubSites.createPageModelFromTemplate(template, templateDictionary, transforms, hubRo);
241
- })
242
- .then(function (interpolated) {
243
- // --------------------------------------------
244
- // TODO: Update hub.js to take an IModel in createPage
245
- // then remove this silliness
246
- var modelTmpl = interpolated;
247
- var options = {
248
- assets: modelTmpl.assets || []
249
- };
250
- // --------------------------------------------
251
- return hubSites.createPage(modelTmpl, options, hubRo);
252
- })
253
- .then(function (page) {
254
- pageModel = page;
255
- // Move the site and initiative to the solution folder
256
- // this is essentially fire and forget. We fail-safe the actual moveItem
257
- // call since it's not critical to the outcome
258
- return moveModelToFolder(page, templateDictionary.folderId, destinationAuthentication);
259
- })
260
- .then(function () {
261
- // Fix the thumbnail
262
- var updateOptions = {
263
- item: {
264
- id: pageModel.item.id
265
- },
266
- params: {
267
- // Pass thumbnail in via params because item property is serialized, which discards a blob
268
- thumbnail: thumbnail
269
- },
270
- authentication: destinationAuthentication
271
- };
272
- return arcgisRestPortal.updateItem(updateOptions);
273
- })
274
- .then(function () {
275
- // Update the template dictionary
276
- // TODO: This should be done in whatever recieves
277
- // the outcome of this promise chain
278
- templateDictionary[template.itemId] = {
279
- itemId: pageModel.item.id
280
- };
281
- // call the progress callback, which also mutates templateDictionary
282
- var finalStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor || 2, pageModel.item.id);
283
- if (!finalStatus) {
284
- // clean up the site we just created
285
- var failSafeRemove = hubCommon.failSafe(hubSites.removePage, { success: true });
286
- return failSafeRemove(pageModel, hubRo).then(function () {
287
- return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
288
- });
289
- }
290
- else {
291
- // finally, return ICreateItemFromTemplateResponse
292
- var response = {
293
- item: __assign(__assign({}, template), pageModel),
294
- id: pageModel.item.id,
295
- type: template.type,
296
- postProcess: true
297
- };
298
- response.item.itemId = pageModel.item.id;
299
- return response;
300
- }
301
- })
302
- .catch(function (ex) {
303
- itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Failed, 0);
304
- throw ex;
305
- });
306
- }
307
- /**
308
- * Post-Process a Page
309
- * Re-interpolate the page item + data w/ the full template dictionary hash
310
- *
311
- * @param id
312
- * @param type
313
- * @param itemInfos
314
- * @param template
315
- * @param templates
316
- * @param templateDictionary
317
- * @param authentication
318
- */
319
- function postProcess(id, type, itemInfos, template, templates, templateDictionary, authentication) {
320
- // create the requestOptions
321
- var hubRo;
322
- // get hubRequestOptions
323
- return solutionCommon.createHubRequestOptions(authentication)
324
- .then(function (ro) {
325
- hubRo = ro;
326
- // get the site model
327
- return hubCommon.getModel(id, { authentication: authentication });
328
- })
329
- .then(function (pageModel) {
330
- // post process the page
331
- return _postProcessPage(pageModel, itemInfos, templateDictionary, hubRo);
332
- });
333
- }
334
- /**
335
- * Check of an item type is a Page
336
- * Hub Page is for ArcGIS Online
337
- * Site Page is for ArcGIS Enterprise
338
- *
339
- * @param itemType
340
- */
341
- function isAPage(itemType) {
342
- var result = false;
343
- if (itemType === "Hub Page" || itemType === "Site Page") {
344
- result = true;
345
- }
346
- return result;
347
- }
335
+ var hubPageProcessor = /*#__PURE__*/Object.freeze({
336
+ __proto__: null,
337
+ convertItemToTemplate: convertItemToTemplate$1,
338
+ createItemFromTemplate: createItemFromTemplate$1,
339
+ postProcess: postProcess$1,
340
+ isAPage: isAPage
341
+ });
348
342
 
349
- var hubPageProcessor = /*#__PURE__*/Object.freeze({
350
- __proto__: null,
351
- convertItemToTemplate: convertItemToTemplate,
352
- createItemFromTemplate: createItemFromTemplate,
353
- postProcess: postProcess,
354
- isAPage: isAPage
355
- });
343
+ /** @license
344
+ * Copyright 2020 Esri
345
+ *
346
+ * Licensed under the Apache License, Version 2.0 (the "License");
347
+ * you may not use this file except in compliance with the License.
348
+ * You may obtain a copy of the License at
349
+ *
350
+ * http://www.apache.org/licenses/LICENSE-2.0
351
+ *
352
+ * Unless required by applicable law or agreed to in writing, software
353
+ * distributed under the License is distributed on an "AS IS" BASIS,
354
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
355
+ * See the License for the specific language governing permissions and
356
+ * limitations under the License.
357
+ */
358
+ /**
359
+ *
360
+ * @param siteModel
361
+ * @param itemInfos
362
+ * @param hubRequestOptions
363
+ */
364
+ function _updateSitePages(siteModel, itemInfos, hubRequestOptions) {
365
+ const pageIds = itemInfos
366
+ .filter(e => {
367
+ return e.type.indexOf("Page") > -1;
368
+ })
369
+ .map(e => e.id);
370
+ // now get all those models
371
+ return Promise.all(pageIds.map(id => {
372
+ return hubCommon.getModel(id, hubRequestOptions);
373
+ })).then((pageModels) => {
374
+ // now delegate back to hub.js internal _updatePages fn
375
+ return hubSites._updatePages(siteModel, pageModels, hubRequestOptions);
376
+ });
377
+ }
356
378
 
357
- /** @license
358
- * Copyright 2020 Esri
359
- *
360
- * Licensed under the Apache License, Version 2.0 (the "License");
361
- * you may not use this file except in compliance with the License.
362
- * You may obtain a copy of the License at
363
- *
364
- * http://www.apache.org/licenses/LICENSE-2.0
365
- *
366
- * Unless required by applicable law or agreed to in writing, software
367
- * distributed under the License is distributed on an "AS IS" BASIS,
368
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
369
- * See the License for the specific language governing permissions and
370
- * limitations under the License.
371
- */
372
- /**
373
- *
374
- * @param siteModel
375
- * @param itemInfos
376
- * @param hubRequestOptions
377
- */
378
- function _updateSitePages(siteModel, itemInfos, hubRequestOptions) {
379
- var pageIds = itemInfos
380
- .filter(function (e) {
381
- return e.type.indexOf("Page") > -1;
382
- })
383
- .map(function (e) { return e.id; });
384
- // now get all those models
385
- return Promise.all(pageIds.map(function (id) {
386
- return hubCommon.getModel(id, hubRequestOptions);
387
- })).then(function (pageModels) {
388
- // now delegate back to hub.js internal _updatePages fn
389
- return hubSites._updatePages(siteModel, pageModels, hubRequestOptions);
390
- });
391
- }
379
+ /**
380
+ * Post Process a Site
381
+ * - share all items to the Hub teams created as part of the site
382
+ * - link any created page to the site item
383
+ * - re-interpolate any remaining item ids that were not direct deps of the site
384
+ *
385
+ * @param siteModel
386
+ * @param itemInfos
387
+ * @param templateDictionary
388
+ * @param hubRequestOptions
389
+ */
390
+ function _postProcessSite(siteModel, itemInfos, templateDictionary, hubRequestOptions) {
391
+ const infosWithoutSite = itemInfos.filter(info => info.id !== siteModel.item.id);
392
+ // convert the itemInfo's into things that look enough like a model
393
+ // that we can call _shareItemsToSiteGroups
394
+ const pseudoModels = infosWithoutSite.map(e => {
395
+ return {
396
+ item: {
397
+ id: e.id,
398
+ type: e.type
399
+ }
400
+ };
401
+ });
402
+ let secondPassPromises = [];
403
+ secondPassPromises = secondPassPromises.concat(hubSites._shareItemsToSiteGroups(siteModel, pseudoModels, hubRequestOptions));
404
+ // we can't use that same trick w/ the page sharing
405
+ // because we really need the models themselves
406
+ // so we delegate to a local function
407
+ secondPassPromises = secondPassPromises.concat(_updateSitePages(siteModel, infosWithoutSite, hubRequestOptions));
408
+ // need to get all the child items and add into site.item.properties.children
409
+ const childItemIds = infosWithoutSite.map(i => i.id);
410
+ siteModel.item.properties.children = childItemIds;
411
+ // re-interpolate the siteModel using the itemInfos
412
+ siteModel = hubSites.interpolateSite(siteModel, templateDictionary, {});
413
+ // and update the model
414
+ secondPassPromises.push(hubSites.updateSite(siteModel, {
415
+ ...hubRequestOptions,
416
+ allowList: null
417
+ }));
418
+ return Promise.all(secondPassPromises).then(() => {
419
+ return true;
420
+ });
421
+ }
392
422
 
393
- /**
394
- * Post Process a Site
395
- * - share all items to the Hub teams created as part of the site
396
- * - link any created page to the site item
397
- * - re-interpolate any remaining item ids that were not direct deps of the site
398
- *
399
- * @param siteModel
400
- * @param itemInfos
401
- * @param templateDictionary
402
- * @param hubRequestOptions
403
- */
404
- function _postProcessSite(siteModel, itemInfos, templateDictionary, hubRequestOptions) {
405
- var infosWithoutSite = itemInfos.filter(function (info) { return info.id !== siteModel.item.id; });
406
- // convert the itemInfo's into things that look enough like a model
407
- // that we can call _shareItemsToSiteGroups
408
- var pseudoModels = infosWithoutSite.map(function (e) {
409
- return {
410
- item: {
411
- id: e.id,
412
- type: e.type
413
- }
414
- };
415
- });
416
- var secondPassPromises = [];
417
- secondPassPromises = secondPassPromises.concat(hubSites._shareItemsToSiteGroups(siteModel, pseudoModels, hubRequestOptions));
418
- // we can't use that same trick w/ the page sharing
419
- // because we really need the models themselves
420
- // so we delegate to a local function
421
- secondPassPromises = secondPassPromises.concat(_updateSitePages(siteModel, infosWithoutSite, hubRequestOptions));
422
- // need to get all the child items and add into site.item.properties.children
423
- var childItemIds = infosWithoutSite.map(function (i) { return i.id; });
424
- siteModel.item.properties.children = childItemIds;
425
- // re-interpolate the siteModel using the itemInfos
426
- siteModel = hubCommon.interpolate(siteModel, templateDictionary, {});
427
- // and update the model
428
- secondPassPromises.push(hubSites.updateSite(siteModel, __assign(__assign({}, hubRequestOptions), { allowList: null })));
429
- return Promise.all(secondPassPromises).then(function () {
430
- return true;
431
- });
432
- }
423
+ /** @license
424
+ * Copyright 2020 Esri
425
+ *
426
+ * Licensed under the Apache License, Version 2.0 (the "License");
427
+ * you may not use this file except in compliance with the License.
428
+ * You may obtain a copy of the License at
429
+ *
430
+ * http://www.apache.org/licenses/LICENSE-2.0
431
+ *
432
+ * Unless required by applicable law or agreed to in writing, software
433
+ * distributed under the License is distributed on an "AS IS" BASIS,
434
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
435
+ * See the License for the specific language governing permissions and
436
+ * limitations under the License.
437
+ */
438
+ /**
439
+ * Converts a Site item into a template.
440
+ *
441
+ * @param solutionItemId The solution to contain the template
442
+ * @param itemInfo Info about the item
443
+ * @param destAuthentication Credentials for requests to the destination organization
444
+ * @param srcAuthentication Credentials for requests to source items (placeholder--not used)
445
+ * @return A promise that will resolve when the template has been created
446
+ */
447
+ function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication = null // eslint-disable-line @typescript-eslint/no-unused-vars
448
+ ) {
449
+ let created = 0;
450
+ let modified = 0;
451
+ let hubRo;
452
+ // get hubRequestOptions
453
+ return solutionCommon.createHubRequestOptions(destAuthentication)
454
+ .then(ro => {
455
+ hubRo = ro;
456
+ return hubSites.getSiteById(itemInfo.id, hubRo);
457
+ })
458
+ .then(siteModel => {
459
+ // We need to save these properties in order to restore them after hub.js deletes them
460
+ created = siteModel.item.created;
461
+ modified = siteModel.item.modified;
462
+ return hubSites.convertSiteToTemplate(siteModel, hubRo);
463
+ })
464
+ .then(tmpl => {
465
+ // add in some stuff Hub.js does not yet add
466
+ tmpl.item.created = created;
467
+ tmpl.item.modified = modified;
468
+ tmpl.item.typeKeywords = hubCommon.without(tmpl.item.typeKeywords, "doNotDelete");
469
+ tmpl.groups = [];
470
+ tmpl.estimatedDeploymentCostFactor = 2;
471
+ tmpl.resources = [];
472
+ if (!solutionCommon.getProp(tmpl, "properties")) {
473
+ tmpl.properties = {};
474
+ }
475
+ // swap out dependency id's to {{<depid>.itemId}}
476
+ // so it will be re-interpolated
477
+ tmpl.dependencies = solutionCommon.dedupe(tmpl.dependencies);
478
+ tmpl = replaceItemIds(tmpl);
479
+ // and return it
480
+ return tmpl;
481
+ });
482
+ }
483
+ /**
484
+ * Handle deployment of Site item templates
485
+ *
486
+ * @export
487
+ * @param {IItemTemplate} template
488
+ * @param {*} templateDictionary
489
+ * @param {UserSession} destinationAuthentication
490
+ * @param {IItemProgressCallback} itemProgressCallback
491
+ * @returns {Promise<ICreateItemFromTemplateResponse>}
492
+ */
493
+ function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
494
+ // let the progress system know we've started...
495
+ const startStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Started, 0);
496
+ // if it returned false, just resolve out
497
+ if (!startStatus) {
498
+ return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
499
+ }
500
+ // TODO: Reassess with resource unification
501
+ if (template.assets && template.resources) {
502
+ delete template.assets;
503
+ }
504
+ // ensure we have a solution object in the templateDictionary hash
505
+ if (!templateDictionary.solution) {
506
+ templateDictionary.solution = {};
507
+ }
508
+ // .title should always be set on the templateDictionary
509
+ templateDictionary.solution.title = templateDictionary.title;
510
+ // TODO: Determine if we need any transforms in this new env
511
+ const transforms = {};
512
+ // create an object to hold the created site through
513
+ // subsequent promise calls
514
+ let siteModel;
515
+ // Create the "siteModel" from the template. Does not save the site item yet
516
+ // Note: depending on licensing and user privs, will also create the team groups
517
+ // and initiative item.
518
+ let hubRo;
519
+ const thumbnail = template.item.thumbnail; // createSiteModelFromTemplate trashes thumbnail
520
+ return solutionCommon.createHubRequestOptions(destinationAuthentication, templateDictionary)
521
+ .then(ro => {
522
+ hubRo = ro;
523
+ return hubSites.createSiteModelFromTemplate(template, templateDictionary, transforms, hubRo);
524
+ })
525
+ .then(interpolated => {
526
+ const options = {
527
+ assets: interpolated.assets || []
528
+ };
529
+ // Now create the item, register for oAuth, register domain etc
530
+ return hubSites.createSite(interpolated, options, hubRo);
531
+ })
532
+ .then(site => {
533
+ // hold onto the site
534
+ siteModel = site;
535
+ // Move the site and initiative to the solution folder
536
+ // this is essentially fire and forget. We fail-safe the actual moveItem
537
+ // call since it's not critical to the outcome
538
+ return moveModelToFolder(site, templateDictionary.folderId, destinationAuthentication);
539
+ })
540
+ .then(() => {
541
+ // Fix the thumbnail
542
+ const updateOptions = {
543
+ item: {
544
+ id: siteModel.item.id
545
+ },
546
+ params: {
547
+ // Pass thumbnail in via params because item property is serialized, which discards a blob
548
+ thumbnail
549
+ },
550
+ authentication: destinationAuthentication
551
+ };
552
+ return arcgisRestPortal.updateItem(updateOptions);
553
+ })
554
+ .then(() => {
555
+ // Update the template dictionary
556
+ // TODO: This should be done in whatever recieves
557
+ // the outcome of this promise chain
558
+ templateDictionary[template.itemId] = {
559
+ itemId: siteModel.item.id
560
+ };
561
+ // call the progress callback, which also mutates templateDictionary
562
+ const finalStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor || 2, siteModel.item.id);
563
+ if (!finalStatus) {
564
+ // clean up the site we just created
565
+ const failSafeRemove = hubCommon.failSafe(hubSites.removeSite, { success: true });
566
+ return failSafeRemove(siteModel, hubRo).then(() => {
567
+ return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
568
+ });
569
+ }
570
+ else {
571
+ // finally, return ICreateItemFromTemplateResponse
572
+ const response = {
573
+ item: {
574
+ ...template,
575
+ ...siteModel
576
+ },
577
+ id: siteModel.item.id,
578
+ type: template.type,
579
+ postProcess: true
580
+ };
581
+ response.item.itemId = siteModel.item.id;
582
+ return response;
583
+ }
584
+ })
585
+ .catch(ex => {
586
+ itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Failed, 0);
587
+ throw ex;
588
+ });
589
+ }
590
+ /**
591
+ * Deployer life-cycle hook allowing the Site Processor
592
+ * a chance to apply final processes to all the items that
593
+ * were created as part of the solution.
594
+ * Specifically this will:
595
+ * - share all items to the content team, and (if created)
596
+ * the core team (depends on user privs)
597
+ * - link all Page items that were created, to the Site
598
+ *
599
+ * @param model
600
+ * @param items
601
+ * @param authentication
602
+ * @param templateDictionary
603
+ */
604
+ function postProcess(id, type, itemInfos, template, templates, templateDictionary, authentication) {
605
+ let hubRo;
606
+ return solutionCommon.createHubRequestOptions(authentication, templateDictionary)
607
+ .then(ro => {
608
+ hubRo = ro;
609
+ // get the site model
610
+ return hubSites.getSiteById(id, hubRo);
611
+ })
612
+ .then(siteModel => {
613
+ // Hub.js does not expect the same structures, so we delegat to a local fn
614
+ return _postProcessSite(siteModel, itemInfos, templateDictionary, hubRo);
615
+ })
616
+ .then(() => {
617
+ // resolve w/ a boolean
618
+ return Promise.resolve(true);
619
+ });
620
+ }
621
+ /**
622
+ * Check of an item type is a Site
623
+ * Hub Site Application is for ArcGIS Online
624
+ * Site Application is for ArcGIS Enterprise
625
+ *
626
+ * @param itemType
627
+ */
628
+ function isASite(itemType) {
629
+ let result = false;
630
+ if (itemType === "Hub Site Application" || itemType === "Site Application") {
631
+ result = true;
632
+ }
633
+ return result;
634
+ }
433
635
 
434
- /** @license
435
- * Copyright 2020 Esri
436
- *
437
- * Licensed under the Apache License, Version 2.0 (the "License");
438
- * you may not use this file except in compliance with the License.
439
- * You may obtain a copy of the License at
440
- *
441
- * http://www.apache.org/licenses/LICENSE-2.0
442
- *
443
- * Unless required by applicable law or agreed to in writing, software
444
- * distributed under the License is distributed on an "AS IS" BASIS,
445
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
446
- * See the License for the specific language governing permissions and
447
- * limitations under the License.
448
- */
449
- /**
450
- * Handle deployment of Site item templates
451
- *
452
- * @export
453
- * @param {IItemTemplate} template
454
- * @param {*} templateDictionary
455
- * @param {UserSession} destinationAuthentication
456
- * @param {IItemProgressCallback} itemProgressCallback
457
- * @returns {Promise<ICreateItemFromTemplateResponse>}
458
- */
459
- function createItemFromTemplate$1(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
460
- // let the progress system know we've started...
461
- var startStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Started, 0);
462
- // if it returned false, just resolve out
463
- if (!startStatus) {
464
- return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
465
- }
466
- // TODO: Reassess with resource unification
467
- if (template.assets && template.resources) {
468
- delete template.assets;
469
- }
470
- // ensure we have a solution object in the templateDictionary hash
471
- if (!templateDictionary.solution) {
472
- templateDictionary.solution = {};
473
- }
474
- // .title should always be set on the templateDictionary
475
- templateDictionary.solution.title = templateDictionary.title;
476
- // TODO: Determine if we need any transforms in this new env
477
- var transforms = {};
478
- // create an object to hold the created site through
479
- // subsequent promise calls
480
- var siteModel;
481
- // Create the "siteModel" from the template. Does not save the site item yet
482
- // Note: depending on licensing and user privs, will also create the team groups
483
- // and initiative item.
484
- var hubRo;
485
- var thumbnail = template.item.thumbnail; // createSiteModelFromTemplate trashes thumbnail
486
- return solutionCommon.createHubRequestOptions(destinationAuthentication, templateDictionary)
487
- .then(function (ro) {
488
- hubRo = ro;
489
- return hubSites.createSiteModelFromTemplate(template, templateDictionary, transforms, hubRo);
490
- })
491
- .then(function (interpolated) {
492
- var options = {
493
- assets: interpolated.assets || []
494
- };
495
- // Now create the item, register for oAuth, register domain etc
496
- return hubSites.createSite(interpolated, options, hubRo);
497
- })
498
- .then(function (site) {
499
- // hold onto the site
500
- siteModel = site;
501
- // Move the site and initiative to the solution folder
502
- // this is essentially fire and forget. We fail-safe the actual moveItem
503
- // call since it's not critical to the outcome
504
- return moveModelToFolder(site, templateDictionary.folderId, destinationAuthentication);
505
- })
506
- .then(function () {
507
- // Fix the thumbnail
508
- var updateOptions = {
509
- item: {
510
- id: siteModel.item.id
511
- },
512
- params: {
513
- // Pass thumbnail in via params because item property is serialized, which discards a blob
514
- thumbnail: thumbnail
515
- },
516
- authentication: destinationAuthentication
517
- };
518
- return arcgisRestPortal.updateItem(updateOptions);
519
- })
520
- .then(function () {
521
- // Update the template dictionary
522
- // TODO: This should be done in whatever recieves
523
- // the outcome of this promise chain
524
- templateDictionary[template.itemId] = {
525
- itemId: siteModel.item.id
526
- };
527
- // call the progress callback, which also mutates templateDictionary
528
- var finalStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor || 2, siteModel.item.id);
529
- if (!finalStatus) {
530
- // clean up the site we just created
531
- var failSafeRemove = hubCommon.failSafe(hubSites.removeSite, { success: true });
532
- return failSafeRemove(siteModel, hubRo).then(function () {
533
- return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
534
- });
535
- }
536
- else {
537
- // finally, return ICreateItemFromTemplateResponse
538
- var response = {
539
- item: __assign(__assign({}, template), siteModel),
540
- id: siteModel.item.id,
541
- type: template.type,
542
- postProcess: true
543
- };
544
- response.item.itemId = siteModel.item.id;
545
- return response;
546
- }
547
- })
548
- .catch(function (ex) {
549
- itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Failed, 0);
550
- throw ex;
551
- });
552
- }
553
- /**
554
- * Converts a Site item into a template.
555
- *
556
- * @param solutionItemId The solution to contain the template
557
- * @param itemInfo Info about the item
558
- * @param authentication Credentials for working with AGO
559
- * @return A promise that will resolve when the template has been created
560
- */
561
- function convertItemToTemplate$1(solutionItemId, itemInfo, authentication) {
562
- var hubRo;
563
- // get hubRequestOptions
564
- return solutionCommon.createHubRequestOptions(authentication)
565
- .then(function (ro) {
566
- hubRo = ro;
567
- return hubSites.getSiteById(itemInfo.id, hubRo);
568
- })
569
- .then(function (siteModel) {
570
- return hubSites.convertSiteToTemplate(siteModel, hubRo);
571
- })
572
- .then(function (tmpl) {
573
- // add in some stuff Hub.js does not yet add
574
- tmpl.item.typeKeywords = hubCommon.without(tmpl.item.typeKeywords, "doNotDelete");
575
- tmpl.groups = [];
576
- tmpl.estimatedDeploymentCostFactor = 2;
577
- tmpl.resources = [];
578
- if (!solutionCommon.getProp(tmpl, "properties")) {
579
- tmpl.properties = {};
580
- }
581
- // swap out dependency id's to {{<depid>.itemId}}
582
- // so it will be re-interpolated
583
- tmpl.dependencies = solutionCommon.dedupe(tmpl.dependencies);
584
- tmpl = replaceItemIds(tmpl);
585
- // and return it
586
- return tmpl;
587
- });
588
- }
589
- /**
590
- * Deployer life-cycle hook allowing the Site Processor
591
- * a chance to apply final processes to all the items that
592
- * were created as part of the solution.
593
- * Specifically this will:
594
- * - share all items to the content team, and (if created)
595
- * the core team (depends on user privs)
596
- * - link all Page items that were created, to the Site
597
- *
598
- * @param model
599
- * @param items
600
- * @param authentication
601
- * @param templateDictionary
602
- */
603
- function postProcess$1(id, type, itemInfos, template, templates, templateDictionary, authentication) {
604
- var hubRo;
605
- return solutionCommon.createHubRequestOptions(authentication, templateDictionary)
606
- .then(function (ro) {
607
- hubRo = ro;
608
- // get the site model
609
- return hubSites.getSiteById(id, hubRo);
610
- })
611
- .then(function (siteModel) {
612
- // Hub.js does not expect the same structures, so we delegat to a local fn
613
- return _postProcessSite(siteModel, itemInfos, templateDictionary, hubRo);
614
- })
615
- .then(function () {
616
- // resolve w/ a boolean
617
- return Promise.resolve(true);
618
- });
619
- }
620
- /**
621
- * Check of an item type is a Site
622
- * Hub Site Application is for ArcGIS Online
623
- * Site Application is for ArcGIS Enterprise
624
- *
625
- * @param itemType
626
- */
627
- function isASite(itemType) {
628
- var result = false;
629
- if (itemType === "Hub Site Application" || itemType === "Site Application") {
630
- result = true;
631
- }
632
- return result;
633
- }
636
+ var hubSiteProcessor = /*#__PURE__*/Object.freeze({
637
+ __proto__: null,
638
+ convertItemToTemplate: convertItemToTemplate,
639
+ createItemFromTemplate: createItemFromTemplate,
640
+ postProcess: postProcess,
641
+ isASite: isASite
642
+ });
634
643
 
635
- var hubSiteProcessor = /*#__PURE__*/Object.freeze({
636
- __proto__: null,
637
- createItemFromTemplate: createItemFromTemplate$1,
638
- convertItemToTemplate: convertItemToTemplate$1,
639
- postProcess: postProcess$1,
640
- isASite: isASite
641
- });
644
+ exports.HubPageProcessor = hubPageProcessor;
645
+ exports.HubSiteProcessor = hubSiteProcessor;
642
646
 
643
- exports.HubPageProcessor = hubPageProcessor;
644
- exports.HubSiteProcessor = hubSiteProcessor;
647
+ Object.defineProperty(exports, '__esModule', { value: true });
645
648
 
646
- Object.defineProperty(exports, '__esModule', { value: true });
647
-
648
- })));
649
+ }));
649
650
  //# sourceMappingURL=hub-types.umd.js.map