@esri/solution-hub-types 4.1.2-alpha.0 → 5.0.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 (35) hide show
  1. package/dist/cjs/helpers/_post-process-page.d.ts +17 -17
  2. package/dist/cjs/helpers/_post-process-page.js +32 -32
  3. package/dist/cjs/helpers/_post-process-page.js.map +1 -1
  4. package/dist/cjs/helpers/_post-process-site.d.ts +29 -29
  5. package/dist/cjs/helpers/_post-process-site.js +50 -50
  6. package/dist/cjs/helpers/_update-site-pages.d.ts +24 -24
  7. package/dist/cjs/helpers/_update-site-pages.js +42 -42
  8. package/dist/cjs/helpers/move-model-to-folder.d.ts +26 -26
  9. package/dist/cjs/helpers/move-model-to-folder.js +49 -49
  10. package/dist/cjs/helpers/replace-item-ids.d.ts +17 -17
  11. package/dist/cjs/helpers/replace-item-ids.js +36 -36
  12. package/dist/cjs/hub-page-processor.d.ts +63 -63
  13. package/dist/cjs/hub-page-processor.js +227 -227
  14. package/dist/cjs/hub-site-processor.d.ts +65 -65
  15. package/dist/cjs/hub-site-processor.js +231 -231
  16. package/dist/cjs/index.d.ts +23 -23
  17. package/dist/cjs/index.js +28 -28
  18. package/dist/esm/helpers/_post-process-page.d.ts +17 -17
  19. package/dist/esm/helpers/_post-process-page.js +28 -28
  20. package/dist/esm/helpers/_post-process-page.js.map +1 -1
  21. package/dist/esm/helpers/_post-process-site.d.ts +29 -29
  22. package/dist/esm/helpers/_post-process-site.js +46 -46
  23. package/dist/esm/helpers/_update-site-pages.d.ts +24 -24
  24. package/dist/esm/helpers/_update-site-pages.js +38 -38
  25. package/dist/esm/helpers/move-model-to-folder.d.ts +26 -26
  26. package/dist/esm/helpers/move-model-to-folder.js +45 -45
  27. package/dist/esm/helpers/replace-item-ids.d.ts +17 -17
  28. package/dist/esm/helpers/replace-item-ids.js +32 -32
  29. package/dist/esm/hub-page-processor.d.ts +63 -63
  30. package/dist/esm/hub-page-processor.js +220 -220
  31. package/dist/esm/hub-site-processor.d.ts +65 -65
  32. package/dist/esm/hub-site-processor.js +224 -224
  33. package/dist/esm/index.d.ts +23 -23
  34. package/dist/esm/index.js +24 -24
  35. package/package.json +3 -3
@@ -1,37 +1,37 @@
1
- "use strict";
2
- /** @license
3
- * Copyright 2020 Esri
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.replaceItemIds = void 0;
19
- const hub_common_1 = require("@esri/hub-common");
20
- function replaceItemIds(template) {
21
- const clone = (0, hub_common_1.cloneObject)(template);
22
- const deps = template.dependencies || [];
23
- // iterate the dependencies
24
- deps.forEach(depId => {
25
- const re = new RegExp(depId, "g");
26
- const replacement = `{{${depId}.itemId}}`;
27
- // we have to do this property-by-property or we would replace the `itemId` prop itself
28
- clone.item = (0, hub_common_1.deepStringReplace)(clone.item, re, replacement);
29
- clone.data = (0, hub_common_1.deepStringReplace)(clone.data, re, replacement);
30
- if (template.properties) {
31
- clone.properties = (0, hub_common_1.deepStringReplace)(clone.properties, re, replacement);
32
- }
33
- });
34
- return clone;
35
- }
36
- exports.replaceItemIds = replaceItemIds;
1
+ "use strict";
2
+ /** @license
3
+ * Copyright 2020 Esri
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.replaceItemIds = void 0;
19
+ const hub_common_1 = require("@esri/hub-common");
20
+ function replaceItemIds(template) {
21
+ const clone = (0, hub_common_1.cloneObject)(template);
22
+ const deps = template.dependencies || [];
23
+ // iterate the dependencies
24
+ deps.forEach(depId => {
25
+ const re = new RegExp(depId, "g");
26
+ const replacement = `{{${depId}.itemId}}`;
27
+ // we have to do this property-by-property or we would replace the `itemId` prop itself
28
+ clone.item = (0, hub_common_1.deepStringReplace)(clone.item, re, replacement);
29
+ clone.data = (0, hub_common_1.deepStringReplace)(clone.data, re, replacement);
30
+ if (template.properties) {
31
+ clone.properties = (0, hub_common_1.deepStringReplace)(clone.properties, re, replacement);
32
+ }
33
+ });
34
+ return clone;
35
+ }
36
+ exports.replaceItemIds = replaceItemIds;
37
37
  //# sourceMappingURL=replace-item-ids.js.map
@@ -1,63 +1,63 @@
1
- /** @license
2
- * Copyright 2018 Esri
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- /**
17
- * Manages the creation and deployment of Hub Page item types.
18
- *
19
- * @module hub-page-processor
20
- */
21
- import { IItemTemplate, IItemProgressCallback, ICreateItemFromTemplateResponse, UserSession } from "@esri/solution-common";
22
- /**
23
- * Converts a Hub Page item into a template.
24
- *
25
- * @param solutionItemId The solution to contain the template
26
- * @param itemInfo Info about the item
27
- * @param destAuthentication Credentials for requests to the destination organization
28
- * @param srcAuthentication Credentials for requests to source items (placeholder--not used)
29
- * @returns A promise that will resolve when the template has been created
30
- */
31
- export declare function convertItemToTemplate(solutionItemId: string, itemInfo: any, destAuthentication: UserSession, srcAuthentication?: UserSession): Promise<IItemTemplate>;
32
- /**
33
- * Handle deployment of Page item templates
34
- *
35
- * @export
36
- * @param {IItemTemplate} template
37
- * @param {*} templateDictionary
38
- * @param {UserSession} destinationAuthentication
39
- * @param {IItemProgressCallback} itemProgressCallback
40
- * @returns {Promise<ICreateItemFromTemplateResponse>}
41
- */
42
- export declare function createItemFromTemplate(template: IItemTemplate, templateDictionary: any, destinationAuthentication: UserSession, itemProgressCallback: IItemProgressCallback): Promise<ICreateItemFromTemplateResponse>;
43
- /**
44
- * Post-Process a Page
45
- * Re-interpolate the page item + data w/ the full template dictionary hash
46
- *
47
- * @param id
48
- * @param type
49
- * @param itemInfos
50
- * @param template
51
- * @param templates
52
- * @param templateDictionary
53
- * @param authentication
54
- */
55
- export declare function postProcess(id: string, type: string, itemInfos: any[], template: any, templates: IItemTemplate[], templateDictionary: any, authentication: UserSession): Promise<boolean>;
56
- /**
57
- * Check of an item type is a Page
58
- * Hub Page is for ArcGIS Online
59
- * Site Page is for ArcGIS Enterprise
60
- *
61
- * @param itemType
62
- */
63
- export declare function isAPage(itemType: string): boolean;
1
+ /** @license
2
+ * Copyright 2018 Esri
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Manages the creation and deployment of Hub Page item types.
18
+ *
19
+ * @module hub-page-processor
20
+ */
21
+ import { IItemTemplate, IItemProgressCallback, ICreateItemFromTemplateResponse, UserSession } from "@esri/solution-common";
22
+ /**
23
+ * Converts a Hub Page item into a template.
24
+ *
25
+ * @param solutionItemId The solution to contain the template
26
+ * @param itemInfo Info about the item
27
+ * @param destAuthentication Credentials for requests to the destination organization
28
+ * @param srcAuthentication Credentials for requests to source items (placeholder--not used)
29
+ * @returns A promise that will resolve when the template has been created
30
+ */
31
+ export declare function convertItemToTemplate(solutionItemId: string, itemInfo: any, destAuthentication: UserSession, srcAuthentication?: UserSession): Promise<IItemTemplate>;
32
+ /**
33
+ * Handle deployment of Page item templates
34
+ *
35
+ * @export
36
+ * @param {IItemTemplate} template
37
+ * @param {*} templateDictionary
38
+ * @param {UserSession} destinationAuthentication
39
+ * @param {IItemProgressCallback} itemProgressCallback
40
+ * @returns {Promise<ICreateItemFromTemplateResponse>}
41
+ */
42
+ export declare function createItemFromTemplate(template: IItemTemplate, templateDictionary: any, destinationAuthentication: UserSession, itemProgressCallback: IItemProgressCallback): Promise<ICreateItemFromTemplateResponse>;
43
+ /**
44
+ * Post-Process a Page
45
+ * Re-interpolate the page item + data w/ the full template dictionary hash
46
+ *
47
+ * @param id
48
+ * @param type
49
+ * @param itemInfos
50
+ * @param template
51
+ * @param templates
52
+ * @param templateDictionary
53
+ * @param authentication
54
+ */
55
+ export declare function postProcess(id: string, type: string, itemInfos: any[], template: any, templates: IItemTemplate[], templateDictionary: any, authentication: UserSession): Promise<boolean>;
56
+ /**
57
+ * Check of an item type is a Page
58
+ * Hub Page is for ArcGIS Online
59
+ * Site Page is for ArcGIS Enterprise
60
+ *
61
+ * @param itemType
62
+ */
63
+ export declare function isAPage(itemType: string): boolean;
@@ -1,228 +1,228 @@
1
- "use strict";
2
- /** @license
3
- * Copyright 2018 Esri
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.isAPage = exports.postProcess = exports.createItemFromTemplate = exports.convertItemToTemplate = void 0;
19
- /**
20
- * Manages the creation and deployment of Hub Page item types.
21
- *
22
- * @module hub-page-processor
23
- */
24
- const solution_common_1 = require("@esri/solution-common");
25
- const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
26
- const hub_common_1 = require("@esri/hub-common");
27
- const hub_sites_1 = require("@esri/hub-sites");
28
- const _post_process_page_1 = require("./helpers/_post-process-page");
29
- const replace_item_ids_1 = require("./helpers/replace-item-ids");
30
- const move_model_to_folder_1 = require("./helpers/move-model-to-folder");
31
- /**
32
- * Converts a Hub Page item into a template.
33
- *
34
- * @param solutionItemId The solution to contain the template
35
- * @param itemInfo Info about the item
36
- * @param destAuthentication Credentials for requests to the destination organization
37
- * @param srcAuthentication Credentials for requests to source items (placeholder--not used)
38
- * @returns A promise that will resolve when the template has been created
39
- */
40
- function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication = null // eslint-disable-line @typescript-eslint/no-unused-vars
41
- ) {
42
- let created = 0;
43
- let modified = 0;
44
- // get the page model and hubRequestOptions
45
- return Promise.all([
46
- (0, hub_common_1.getModel)(itemInfo.id, { authentication: destAuthentication }),
47
- (0, solution_common_1.createHubRequestOptions)(destAuthentication)
48
- ])
49
- .then(([pageModel, ro]) => {
50
- // We need to save these properties in order to restore them after hub.js deletes them
51
- created = pageModel.item.created;
52
- modified = pageModel.item.modified;
53
- return (0, hub_sites_1.convertPageToTemplate)(pageModel, ro);
54
- })
55
- .then(tmpl => {
56
- // add in some stuff Hub.js does not yet add
57
- tmpl.item.created = created;
58
- tmpl.item.modified = modified;
59
- tmpl.item.typeKeywords = (0, hub_common_1.without)(tmpl.item.typeKeywords, "doNotDelete");
60
- tmpl.groups = [];
61
- tmpl.estimatedDeploymentCostFactor = 2;
62
- tmpl.resources = [];
63
- if (!(0, hub_common_1.getProp)(tmpl, "properties")) {
64
- tmpl.properties = {};
65
- }
66
- // swap out dependency id's to {{<depid>.itemId}}
67
- // so it will be re-interpolated
68
- tmpl = (0, replace_item_ids_1.replaceItemIds)(tmpl);
69
- // and return it
70
- return tmpl;
71
- });
72
- }
73
- exports.convertItemToTemplate = convertItemToTemplate;
74
- /**
75
- * Handle deployment of Page item templates
76
- *
77
- * @export
78
- * @param {IItemTemplate} template
79
- * @param {*} templateDictionary
80
- * @param {UserSession} destinationAuthentication
81
- * @param {IItemProgressCallback} itemProgressCallback
82
- * @returns {Promise<ICreateItemFromTemplateResponse>}
83
- */
84
- function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
85
- // let the progress system know we've started...
86
- const startStatus = itemProgressCallback(template.itemId, solution_common_1.EItemProgressStatus.Started, 0);
87
- // and if it returned false, just resolve out
88
- if (!startStatus) {
89
- return Promise.resolve((0, solution_common_1.generateEmptyCreationResponse)(template.type));
90
- }
91
- // TODO: Reassess with resource unification
92
- if (template.assets && template.resources) {
93
- delete template.assets;
94
- }
95
- // solutionItemExtent is in geographic, but it's a string, and we want/need a bbox
96
- // and Hub templates expect it in organization.defaultExtentBBox
97
- if (templateDictionary.solutionItemExtent) {
98
- const parts = templateDictionary.solutionItemExtent.split(",");
99
- templateDictionary.organization.defaultExtentBBox = [
100
- [parts[0], parts[1]],
101
- [parts[2], parts[3]]
102
- ];
103
- }
104
- // TODO: Determine if we need any transforms in this new env
105
- const transforms = {};
106
- // create an object to hold the created site through
107
- // subsequent promise calls
108
- let pageModel;
109
- let hubRo;
110
- const thumbnail = template.item.thumbnail; // createPageModelFromTemplate trashes thumbnail
111
- return (0, solution_common_1.createHubRequestOptions)(destinationAuthentication, templateDictionary)
112
- .then(ro => {
113
- hubRo = ro;
114
- return (0, hub_sites_1.createPageModelFromTemplate)(template, templateDictionary, transforms, hubRo);
115
- })
116
- .then((interpolated) => {
117
- // --------------------------------------------
118
- // TODO: Update hub.js to take an IModel in createPage
119
- // then remove this silliness
120
- const modelTmpl = interpolated;
121
- const options = {
122
- assets: modelTmpl.assets || []
123
- };
124
- // --------------------------------------------
125
- return (0, hub_sites_1.createPage)(modelTmpl, options, hubRo);
126
- })
127
- .then(page => {
128
- pageModel = page;
129
- // Move the site and initiative to the solution folder
130
- // this is essentially fire and forget. We fail-safe the actual moveItem
131
- // call since it's not critical to the outcome
132
- return (0, move_model_to_folder_1.moveModelToFolder)(page, templateDictionary.folderId, destinationAuthentication);
133
- })
134
- .then(() => {
135
- // Fix the thumbnail
136
- const updateOptions = {
137
- item: {
138
- id: pageModel.item.id
139
- },
140
- params: {
141
- // Pass thumbnail in via params because item property is serialized, which discards a blob
142
- thumbnail
143
- },
144
- authentication: destinationAuthentication
145
- };
146
- return (0, arcgis_rest_portal_1.updateItem)(updateOptions);
147
- })
148
- .then(() => {
149
- // Update the template dictionary
150
- // TODO: This should be done in whatever recieves
151
- // the outcome of this promise chain
152
- templateDictionary[template.itemId] = {
153
- itemId: pageModel.item.id
154
- };
155
- // call the progress callback, which also mutates templateDictionary
156
- const finalStatus = itemProgressCallback(template.itemId, solution_common_1.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor || 2, pageModel.item.id);
157
- if (!finalStatus) {
158
- // clean up the site we just created
159
- const failSafeRemove = (0, hub_common_1.failSafe)(hub_sites_1.removePage, { success: true });
160
- return failSafeRemove(pageModel, hubRo).then(() => {
161
- return Promise.resolve((0, solution_common_1.generateEmptyCreationResponse)(template.type));
162
- });
163
- }
164
- else {
165
- // finally, return ICreateItemFromTemplateResponse
166
- const response = {
167
- item: {
168
- ...template,
169
- ...(0, solution_common_1.convertIModel)(pageModel)
170
- },
171
- id: pageModel.item.id,
172
- type: template.type,
173
- postProcess: true
174
- };
175
- response.item.itemId = pageModel.item.id;
176
- return response;
177
- }
178
- })
179
- .catch(ex => {
180
- itemProgressCallback(template.itemId, solution_common_1.EItemProgressStatus.Failed, 0);
181
- throw ex;
182
- });
183
- }
184
- exports.createItemFromTemplate = createItemFromTemplate;
185
- /**
186
- * Post-Process a Page
187
- * Re-interpolate the page item + data w/ the full template dictionary hash
188
- *
189
- * @param id
190
- * @param type
191
- * @param itemInfos
192
- * @param template
193
- * @param templates
194
- * @param templateDictionary
195
- * @param authentication
196
- */
197
- function postProcess(id, type, itemInfos, template, templates, templateDictionary, authentication) {
198
- // create the requestOptions
199
- let hubRo;
200
- // get hubRequestOptions
201
- return (0, solution_common_1.createHubRequestOptions)(authentication)
202
- .then(ro => {
203
- hubRo = ro;
204
- // get the site model
205
- return (0, hub_common_1.getModel)(id, { authentication });
206
- })
207
- .then(pageModel => {
208
- // post process the page
209
- return (0, _post_process_page_1._postProcessPage)(pageModel, itemInfos, templateDictionary, hubRo);
210
- });
211
- }
212
- exports.postProcess = postProcess;
213
- /**
214
- * Check of an item type is a Page
215
- * Hub Page is for ArcGIS Online
216
- * Site Page is for ArcGIS Enterprise
217
- *
218
- * @param itemType
219
- */
220
- function isAPage(itemType) {
221
- let result = false;
222
- if (itemType === "Hub Page" || itemType === "Site Page") {
223
- result = true;
224
- }
225
- return result;
226
- }
227
- exports.isAPage = isAPage;
1
+ "use strict";
2
+ /** @license
3
+ * Copyright 2018 Esri
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.isAPage = exports.postProcess = exports.createItemFromTemplate = exports.convertItemToTemplate = void 0;
19
+ /**
20
+ * Manages the creation and deployment of Hub Page item types.
21
+ *
22
+ * @module hub-page-processor
23
+ */
24
+ const solution_common_1 = require("@esri/solution-common");
25
+ const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
26
+ const hub_common_1 = require("@esri/hub-common");
27
+ const hub_sites_1 = require("@esri/hub-sites");
28
+ const _post_process_page_1 = require("./helpers/_post-process-page");
29
+ const replace_item_ids_1 = require("./helpers/replace-item-ids");
30
+ const move_model_to_folder_1 = require("./helpers/move-model-to-folder");
31
+ /**
32
+ * Converts a Hub Page item into a template.
33
+ *
34
+ * @param solutionItemId The solution to contain the template
35
+ * @param itemInfo Info about the item
36
+ * @param destAuthentication Credentials for requests to the destination organization
37
+ * @param srcAuthentication Credentials for requests to source items (placeholder--not used)
38
+ * @returns A promise that will resolve when the template has been created
39
+ */
40
+ function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication = null // eslint-disable-line @typescript-eslint/no-unused-vars
41
+ ) {
42
+ let created = 0;
43
+ let modified = 0;
44
+ // get the page model and hubRequestOptions
45
+ return Promise.all([
46
+ (0, hub_common_1.getModel)(itemInfo.id, { authentication: destAuthentication }),
47
+ (0, solution_common_1.createHubRequestOptions)(destAuthentication)
48
+ ])
49
+ .then(([pageModel, ro]) => {
50
+ // We need to save these properties in order to restore them after hub.js deletes them
51
+ created = pageModel.item.created;
52
+ modified = pageModel.item.modified;
53
+ return (0, hub_sites_1.convertPageToTemplate)(pageModel, ro);
54
+ })
55
+ .then(tmpl => {
56
+ // add in some stuff Hub.js does not yet add
57
+ tmpl.item.created = created;
58
+ tmpl.item.modified = modified;
59
+ tmpl.item.typeKeywords = (0, hub_common_1.without)(tmpl.item.typeKeywords, "doNotDelete");
60
+ tmpl.groups = [];
61
+ tmpl.estimatedDeploymentCostFactor = 2;
62
+ tmpl.resources = [];
63
+ if (!(0, hub_common_1.getProp)(tmpl, "properties")) {
64
+ tmpl.properties = {};
65
+ }
66
+ // swap out dependency id's to {{<depid>.itemId}}
67
+ // so it will be re-interpolated
68
+ tmpl = (0, replace_item_ids_1.replaceItemIds)(tmpl);
69
+ // and return it
70
+ return tmpl;
71
+ });
72
+ }
73
+ exports.convertItemToTemplate = convertItemToTemplate;
74
+ /**
75
+ * Handle deployment of Page item templates
76
+ *
77
+ * @export
78
+ * @param {IItemTemplate} template
79
+ * @param {*} templateDictionary
80
+ * @param {UserSession} destinationAuthentication
81
+ * @param {IItemProgressCallback} itemProgressCallback
82
+ * @returns {Promise<ICreateItemFromTemplateResponse>}
83
+ */
84
+ function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
85
+ // let the progress system know we've started...
86
+ const startStatus = itemProgressCallback(template.itemId, solution_common_1.EItemProgressStatus.Started, 0);
87
+ // and if it returned false, just resolve out
88
+ if (!startStatus) {
89
+ return Promise.resolve((0, solution_common_1.generateEmptyCreationResponse)(template.type));
90
+ }
91
+ // TODO: Reassess with resource unification
92
+ if (template.assets && template.resources) {
93
+ delete template.assets;
94
+ }
95
+ // solutionItemExtent is in geographic, but it's a string, and we want/need a bbox
96
+ // and Hub templates expect it in organization.defaultExtentBBox
97
+ if (templateDictionary.solutionItemExtent) {
98
+ const parts = templateDictionary.solutionItemExtent.split(",");
99
+ templateDictionary.organization.defaultExtentBBox = [
100
+ [parts[0], parts[1]],
101
+ [parts[2], parts[3]]
102
+ ];
103
+ }
104
+ // TODO: Determine if we need any transforms in this new env
105
+ const transforms = {};
106
+ // create an object to hold the created site through
107
+ // subsequent promise calls
108
+ let pageModel;
109
+ let hubRo;
110
+ const thumbnail = template.item.thumbnail; // createPageModelFromTemplate trashes thumbnail
111
+ return (0, solution_common_1.createHubRequestOptions)(destinationAuthentication, templateDictionary)
112
+ .then(ro => {
113
+ hubRo = ro;
114
+ return (0, hub_sites_1.createPageModelFromTemplate)(template, templateDictionary, transforms, hubRo);
115
+ })
116
+ .then((interpolated) => {
117
+ // --------------------------------------------
118
+ // TODO: Update hub.js to take an IModel in createPage
119
+ // then remove this silliness
120
+ const modelTmpl = interpolated;
121
+ const options = {
122
+ assets: modelTmpl.assets || []
123
+ };
124
+ // --------------------------------------------
125
+ return (0, hub_sites_1.createPage)(modelTmpl, options, hubRo);
126
+ })
127
+ .then(page => {
128
+ pageModel = page;
129
+ // Move the site and initiative to the solution folder
130
+ // this is essentially fire and forget. We fail-safe the actual moveItem
131
+ // call since it's not critical to the outcome
132
+ return (0, move_model_to_folder_1.moveModelToFolder)(page, templateDictionary.folderId, destinationAuthentication);
133
+ })
134
+ .then(() => {
135
+ // Fix the thumbnail
136
+ const updateOptions = {
137
+ item: {
138
+ id: pageModel.item.id
139
+ },
140
+ params: {
141
+ // Pass thumbnail in via params because item property is serialized, which discards a blob
142
+ thumbnail
143
+ },
144
+ authentication: destinationAuthentication
145
+ };
146
+ return (0, arcgis_rest_portal_1.updateItem)(updateOptions);
147
+ })
148
+ .then(() => {
149
+ // Update the template dictionary
150
+ // TODO: This should be done in whatever recieves
151
+ // the outcome of this promise chain
152
+ templateDictionary[template.itemId] = {
153
+ itemId: pageModel.item.id
154
+ };
155
+ // call the progress callback, which also mutates templateDictionary
156
+ const finalStatus = itemProgressCallback(template.itemId, solution_common_1.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor || 2, pageModel.item.id);
157
+ if (!finalStatus) {
158
+ // clean up the site we just created
159
+ const failSafeRemove = (0, hub_common_1.failSafe)(hub_sites_1.removePage, { success: true });
160
+ return failSafeRemove(pageModel, hubRo).then(() => {
161
+ return Promise.resolve((0, solution_common_1.generateEmptyCreationResponse)(template.type));
162
+ });
163
+ }
164
+ else {
165
+ // finally, return ICreateItemFromTemplateResponse
166
+ const response = {
167
+ item: {
168
+ ...template,
169
+ ...(0, solution_common_1.convertIModel)(pageModel)
170
+ },
171
+ id: pageModel.item.id,
172
+ type: template.type,
173
+ postProcess: true
174
+ };
175
+ response.item.itemId = pageModel.item.id;
176
+ return response;
177
+ }
178
+ })
179
+ .catch(ex => {
180
+ itemProgressCallback(template.itemId, solution_common_1.EItemProgressStatus.Failed, 0);
181
+ throw ex;
182
+ });
183
+ }
184
+ exports.createItemFromTemplate = createItemFromTemplate;
185
+ /**
186
+ * Post-Process a Page
187
+ * Re-interpolate the page item + data w/ the full template dictionary hash
188
+ *
189
+ * @param id
190
+ * @param type
191
+ * @param itemInfos
192
+ * @param template
193
+ * @param templates
194
+ * @param templateDictionary
195
+ * @param authentication
196
+ */
197
+ function postProcess(id, type, itemInfos, template, templates, templateDictionary, authentication) {
198
+ // create the requestOptions
199
+ let hubRo;
200
+ // get hubRequestOptions
201
+ return (0, solution_common_1.createHubRequestOptions)(authentication)
202
+ .then(ro => {
203
+ hubRo = ro;
204
+ // get the site model
205
+ return (0, hub_common_1.getModel)(id, { authentication });
206
+ })
207
+ .then(pageModel => {
208
+ // post process the page
209
+ return (0, _post_process_page_1._postProcessPage)(pageModel, itemInfos, templateDictionary, hubRo);
210
+ });
211
+ }
212
+ exports.postProcess = postProcess;
213
+ /**
214
+ * Check of an item type is a Page
215
+ * Hub Page is for ArcGIS Online
216
+ * Site Page is for ArcGIS Enterprise
217
+ *
218
+ * @param itemType
219
+ */
220
+ function isAPage(itemType) {
221
+ let result = false;
222
+ if (itemType === "Hub Page" || itemType === "Site Page") {
223
+ result = true;
224
+ }
225
+ return result;
226
+ }
227
+ exports.isAPage = isAPage;
228
228
  //# sourceMappingURL=hub-page-processor.js.map