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