@esri/solution-creator 4.1.2 → 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/createItemTemplate.d.ts +108 -108
- package/dist/cjs/createItemTemplate.js +438 -435
- package/dist/cjs/createItemTemplate.js.map +1 -1
- package/dist/cjs/creator.d.ts +97 -97
- package/dist/cjs/creator.js +278 -278
- package/dist/cjs/helpers/add-content-to-solution.d.ts +126 -126
- package/dist/cjs/helpers/add-content-to-solution.js +464 -464
- package/dist/cjs/helpers/template.d.ts +30 -30
- package/dist/cjs/helpers/template.js +48 -48
- package/dist/cjs/index.d.ts +23 -23
- package/dist/cjs/index.js +26 -26
- package/dist/cjs/module-map.d.ts +23 -23
- package/dist/cjs/module-map.js +195 -195
- package/dist/esm/createItemTemplate.d.ts +108 -108
- package/dist/esm/createItemTemplate.js +426 -423
- package/dist/esm/createItemTemplate.js.map +1 -1
- package/dist/esm/creator.d.ts +97 -97
- package/dist/esm/creator.js +267 -267
- package/dist/esm/helpers/add-content-to-solution.d.ts +126 -126
- package/dist/esm/helpers/add-content-to-solution.js +448 -448
- package/dist/esm/helpers/template.d.ts +30 -30
- package/dist/esm/helpers/template.js +43 -43
- package/dist/esm/index.d.ts +23 -23
- package/dist/esm/index.js +23 -23
- package/dist/esm/module-map.d.ts +23 -23
- package/dist/esm/module-map.js +191 -191
- package/package.json +12 -12
package/dist/cjs/creator.js
CHANGED
|
@@ -1,279 +1,279 @@
|
|
|
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._getDeploymentProperty = exports._getDeploymentProperties = exports._createSolutionItemModel = exports._createSolutionItem = exports._createSolutionFromItemIds = exports._addThumbnailFileToCreateOptions = exports._applySourceToCreateOptions = exports.createSolution = void 0;
|
|
19
|
-
/**
|
|
20
|
-
* Manages the creation of a Solution item.
|
|
21
|
-
*
|
|
22
|
-
* @module creator
|
|
23
|
-
*/
|
|
24
|
-
const solution_common_1 = require("@esri/solution-common");
|
|
25
|
-
const hub_common_1 = require("@esri/hub-common");
|
|
26
|
-
const add_content_to_solution_1 = require("./helpers/add-content-to-solution");
|
|
27
|
-
// Simple no-op to clean up progressCallback management
|
|
28
|
-
const noOp = () => { };
|
|
29
|
-
/**
|
|
30
|
-
* Creates a solution item.
|
|
31
|
-
*
|
|
32
|
-
* @param sourceId AGO id of group whose contents are to be added to solution or of an item to convert into a solution
|
|
33
|
-
* @param srcAuthentication Credentials for requests to source items
|
|
34
|
-
* @param destAuthentication Credentials for the requests to destination solution
|
|
35
|
-
* @param options Customizations for creating the solution
|
|
36
|
-
* @returns A promise that resolves with the AGO id of the new solution
|
|
37
|
-
*/
|
|
38
|
-
function createSolution(sourceId, srcAuthentication, destAuthentication, options) {
|
|
39
|
-
const createOptions = options || {};
|
|
40
|
-
const progressCb = createOptions.progressCallback || noOp;
|
|
41
|
-
createOptions.templateDictionary = Object.assign({}, createOptions.templateDictionary);
|
|
42
|
-
progressCb(1); // let the caller know that we've started
|
|
43
|
-
// Assume that source is a group and try to get group's information
|
|
44
|
-
return Promise.all([
|
|
45
|
-
(0, solution_common_1.getGroupBase)(sourceId, srcAuthentication),
|
|
46
|
-
(0, solution_common_1.getGroupContents)(sourceId, srcAuthentication),
|
|
47
|
-
(0, solution_common_1.getVelocityUrlBase)(srcAuthentication, createOptions.templateDictionary)
|
|
48
|
-
])
|
|
49
|
-
.then(
|
|
50
|
-
// Group fetches worked; assumption was correct
|
|
51
|
-
responses => {
|
|
52
|
-
createOptions.itemIds = responses[1];
|
|
53
|
-
progressCb(15);
|
|
54
|
-
return new Promise(resolve => {
|
|
55
|
-
// Update the createOptions with values from the group
|
|
56
|
-
resolve(_applySourceToCreateOptions(createOptions, responses[0], srcAuthentication, true));
|
|
57
|
-
});
|
|
58
|
-
},
|
|
59
|
-
// Assumption incorrect; try source as an item
|
|
60
|
-
() => {
|
|
61
|
-
return new Promise((resolve, reject) => {
|
|
62
|
-
createOptions.itemIds = [sourceId];
|
|
63
|
-
(0, solution_common_1.getItemBase)(sourceId, srcAuthentication).then(
|
|
64
|
-
// Update the createOptions with values from the item
|
|
65
|
-
itemBase => resolve(_applySourceToCreateOptions(createOptions, itemBase, srcAuthentication, false)), reject);
|
|
66
|
-
});
|
|
67
|
-
})
|
|
68
|
-
.then(createOptions => {
|
|
69
|
-
return new Promise((resolve, reject) => {
|
|
70
|
-
Promise.all([
|
|
71
|
-
(0, solution_common_1.getPortal)("", srcAuthentication),
|
|
72
|
-
(0, solution_common_1.getUser)(srcAuthentication)
|
|
73
|
-
]).then(responses => {
|
|
74
|
-
// check tracking
|
|
75
|
-
const [portalResponse, userResponse] = responses;
|
|
76
|
-
(0, solution_common_1.setLocationTrackingEnabled)(portalResponse, userResponse, createOptions.templateDictionary);
|
|
77
|
-
resolve(createOptions);
|
|
78
|
-
}, reject);
|
|
79
|
-
});
|
|
80
|
-
})
|
|
81
|
-
.then(
|
|
82
|
-
// Use a copy of the thumbnail rather than a URL to it
|
|
83
|
-
createOptions => {
|
|
84
|
-
return _addThumbnailFileToCreateOptions(createOptions, srcAuthentication);
|
|
85
|
-
})
|
|
86
|
-
.then(
|
|
87
|
-
// Create a solution
|
|
88
|
-
createOptions => {
|
|
89
|
-
return _createSolutionFromItemIds(createOptions, srcAuthentication, destAuthentication);
|
|
90
|
-
})
|
|
91
|
-
.then(
|
|
92
|
-
// Successfully created solution
|
|
93
|
-
createdSolutionId => {
|
|
94
|
-
progressCb(100); // finished
|
|
95
|
-
return createdSolutionId;
|
|
96
|
-
},
|
|
97
|
-
// Error fetching group, group contents, or item, or error creating solution from ids
|
|
98
|
-
error => {
|
|
99
|
-
progressCb(1);
|
|
100
|
-
console.error(error);
|
|
101
|
-
throw error;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
exports.createSolution = createSolution;
|
|
105
|
-
/**
|
|
106
|
-
* Update the createOptions with the group properties
|
|
107
|
-
*
|
|
108
|
-
* @param createOptions
|
|
109
|
-
* @param sourceInfo
|
|
110
|
-
* @param authentication
|
|
111
|
-
* @param isGroup Boolean to indicate if the files are associated with a group or item
|
|
112
|
-
* @private
|
|
113
|
-
*/
|
|
114
|
-
function _applySourceToCreateOptions(createOptions, sourceInfo, srcAuthentication, isGroup = false) {
|
|
115
|
-
// Create a solution from the group's or item's contents,
|
|
116
|
-
// using the group's or item's information as defaults for the solution item
|
|
117
|
-
["title", "snippet", "description", "tags"].forEach(prop => {
|
|
118
|
-
createOptions[prop] = createOptions[prop] ?? sourceInfo[prop];
|
|
119
|
-
});
|
|
120
|
-
if (!createOptions.thumbnailurl && sourceInfo.thumbnail) {
|
|
121
|
-
// Get the full path to the thumbnail
|
|
122
|
-
createOptions.thumbnailurl = (0, solution_common_1.generateSourceThumbnailUrl)(srcAuthentication.portal, sourceInfo.id, sourceInfo.thumbnail, isGroup);
|
|
123
|
-
delete sourceInfo.thumbnail;
|
|
124
|
-
}
|
|
125
|
-
return createOptions;
|
|
126
|
-
}
|
|
127
|
-
exports._applySourceToCreateOptions = _applySourceToCreateOptions;
|
|
128
|
-
/**
|
|
129
|
-
* Update the createOptions with the thumbnail file
|
|
130
|
-
*
|
|
131
|
-
* @param createOptions
|
|
132
|
-
* @param srcAuthentication
|
|
133
|
-
* @private
|
|
134
|
-
*/
|
|
135
|
-
function _addThumbnailFileToCreateOptions(createOptions, srcAuthentication) {
|
|
136
|
-
return new Promise(resolve => {
|
|
137
|
-
if (!createOptions.thumbnail && createOptions.thumbnailurl) {
|
|
138
|
-
// Figure out the thumbnail's filename
|
|
139
|
-
const filename = (0, solution_common_1.getFilenameFromUrl)(createOptions.thumbnailurl) || "thumbnail";
|
|
140
|
-
const thumbnailurl = (0, solution_common_1.appendQueryParam)(createOptions.thumbnailurl, "w=400");
|
|
141
|
-
delete createOptions.thumbnailurl;
|
|
142
|
-
// Fetch the thumbnail
|
|
143
|
-
(0, solution_common_1.getBlobAsFile)(thumbnailurl, filename, srcAuthentication).then(thumbnail => {
|
|
144
|
-
createOptions.thumbnail = thumbnail;
|
|
145
|
-
resolve(createOptions);
|
|
146
|
-
}, () => {
|
|
147
|
-
resolve(createOptions);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
resolve(createOptions);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
exports._addThumbnailFileToCreateOptions = _addThumbnailFileToCreateOptions;
|
|
156
|
-
/**
|
|
157
|
-
* Creates a solution item using a list of AGO item ids.
|
|
158
|
-
*
|
|
159
|
-
* @param options Customizations for creating the solution
|
|
160
|
-
* @param srcAuthentication Credentials for requests to source items
|
|
161
|
-
* @param destAuthentication Credentials for the requests to destination solution
|
|
162
|
-
* @returns A promise that resolves with the AGO id of the new solution; solution item is deleted if its
|
|
163
|
-
* there is a problem updating it
|
|
164
|
-
* @private
|
|
165
|
-
*/
|
|
166
|
-
function _createSolutionFromItemIds(options, srcAuthentication, destAuthentication) {
|
|
167
|
-
let solutionId = "";
|
|
168
|
-
// Create a solution from the list of items
|
|
169
|
-
return _createSolutionItem(destAuthentication, options)
|
|
170
|
-
.then(id => {
|
|
171
|
-
solutionId = id;
|
|
172
|
-
// Add list of items to the new solution
|
|
173
|
-
return (0, add_content_to_solution_1.addContentToSolution)(solutionId, options, srcAuthentication, destAuthentication);
|
|
174
|
-
})
|
|
175
|
-
.catch(addError => {
|
|
176
|
-
// If the solution item got created, delete it
|
|
177
|
-
if (solutionId) {
|
|
178
|
-
const failSafeRemove = (0, hub_common_1.failSafe)(solution_common_1.removeItem, { success: true });
|
|
179
|
-
return failSafeRemove(solutionId, destAuthentication).then(() => {
|
|
180
|
-
throw addError;
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
throw addError;
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
exports._createSolutionFromItemIds = _createSolutionFromItemIds;
|
|
189
|
-
/**
|
|
190
|
-
* Creates an empty solution item.
|
|
191
|
-
*
|
|
192
|
-
* @param authentication Credentials for the request
|
|
193
|
-
* @param options Customizations for creating the solution
|
|
194
|
-
* @returns A promise that resolves with the AGO id of the new solution; solution item is deleted if its
|
|
195
|
-
* there is a problem updating its thumbnail
|
|
196
|
-
* @private
|
|
197
|
-
*/
|
|
198
|
-
function _createSolutionItem(authentication, options) {
|
|
199
|
-
const model = _createSolutionItemModel(options);
|
|
200
|
-
// Create new solution item
|
|
201
|
-
delete model.item.thumbnailurl;
|
|
202
|
-
model.item.thumbnail = options?.thumbnail;
|
|
203
|
-
return (0, solution_common_1.createItemWithData)(model.item, model.data, authentication, options?.folderId).then(createResponse => {
|
|
204
|
-
return Promise.resolve(createResponse.id);
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
exports._createSolutionItem = _createSolutionItem;
|
|
208
|
-
/**
|
|
209
|
-
* Create the Solution Item model to be used to create
|
|
210
|
-
* the Solution Item itself
|
|
211
|
-
*
|
|
212
|
-
* @param options
|
|
213
|
-
* @private
|
|
214
|
-
*/
|
|
215
|
-
function _createSolutionItemModel(options) {
|
|
216
|
-
// Solution uses all supplied tags but for deploy.* tags; that information goes into properties
|
|
217
|
-
const creationTags = options?.tags ?? [];
|
|
218
|
-
const solutionItem = {
|
|
219
|
-
type: "Solution",
|
|
220
|
-
title: options?.title ?? (0, solution_common_1.createShortId)(),
|
|
221
|
-
snippet: options?.snippet ?? "",
|
|
222
|
-
description: options?.description ?? "",
|
|
223
|
-
properties: {
|
|
224
|
-
schemaVersion: solution_common_1.CURRENT_SCHEMA_VERSION
|
|
225
|
-
},
|
|
226
|
-
thumbnailurl: options?.thumbnailurl ?? "",
|
|
227
|
-
tags: creationTags.filter((tag) => !tag.startsWith("deploy.")),
|
|
228
|
-
typeKeywords: ["Solution", "Template"].concat(_getDeploymentProperties(creationTags))
|
|
229
|
-
};
|
|
230
|
-
// ensure that snippet and description are not nefarious
|
|
231
|
-
const sanitizedItem = (0, solution_common_1.sanitizeJSON)(solutionItem);
|
|
232
|
-
const addlKeywords = options?.additionalTypeKeywords || [];
|
|
233
|
-
sanitizedItem.typeKeywords = [].concat(solutionItem.typeKeywords, addlKeywords);
|
|
234
|
-
const solutionData = {
|
|
235
|
-
metadata: {},
|
|
236
|
-
templates: []
|
|
237
|
-
};
|
|
238
|
-
return {
|
|
239
|
-
item: sanitizedItem,
|
|
240
|
-
data: solutionData
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
exports._createSolutionItemModel = _createSolutionItemModel;
|
|
244
|
-
/**
|
|
245
|
-
* Gets the deploy.id and deploy.version tag values.
|
|
246
|
-
*
|
|
247
|
-
* @param tags A list of item tags
|
|
248
|
-
* @returns A list containing the two values found in the tags, or defaulting to a new GUID and "1.0", respectively,
|
|
249
|
-
* as needed
|
|
250
|
-
* @private
|
|
251
|
-
*/
|
|
252
|
-
function _getDeploymentProperties(tags) {
|
|
253
|
-
return [
|
|
254
|
-
"solutionid-" +
|
|
255
|
-
(_getDeploymentProperty("deploy.id.", tags) ?? (0, solution_common_1.createLongId)()),
|
|
256
|
-
"solutionversion-" +
|
|
257
|
-
(_getDeploymentProperty("deploy.version.", tags) ?? "1.0")
|
|
258
|
-
];
|
|
259
|
-
}
|
|
260
|
-
exports._getDeploymentProperties = _getDeploymentProperties;
|
|
261
|
-
/**
|
|
262
|
-
* Searches for a tag that has the specified prefix and returns the rest of the tag following that prefix.
|
|
263
|
-
*
|
|
264
|
-
* @param desiredTagPrefix Tag prefix to look for
|
|
265
|
-
* @param tags A list of item tags
|
|
266
|
-
* @returns The extracted value of the first matching tag or null if a tag with the specified prefix is not found
|
|
267
|
-
* @private
|
|
268
|
-
*/
|
|
269
|
-
function _getDeploymentProperty(desiredTagPrefix, tags) {
|
|
270
|
-
const foundTagAsList = tags.filter(tag => tag.startsWith(desiredTagPrefix));
|
|
271
|
-
if (foundTagAsList.length > 0) {
|
|
272
|
-
return foundTagAsList[0].substr(desiredTagPrefix.length);
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
return null;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
exports._getDeploymentProperty = _getDeploymentProperty;
|
|
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._getDeploymentProperty = exports._getDeploymentProperties = exports._createSolutionItemModel = exports._createSolutionItem = exports._createSolutionFromItemIds = exports._addThumbnailFileToCreateOptions = exports._applySourceToCreateOptions = exports.createSolution = void 0;
|
|
19
|
+
/**
|
|
20
|
+
* Manages the creation of a Solution item.
|
|
21
|
+
*
|
|
22
|
+
* @module creator
|
|
23
|
+
*/
|
|
24
|
+
const solution_common_1 = require("@esri/solution-common");
|
|
25
|
+
const hub_common_1 = require("@esri/hub-common");
|
|
26
|
+
const add_content_to_solution_1 = require("./helpers/add-content-to-solution");
|
|
27
|
+
// Simple no-op to clean up progressCallback management
|
|
28
|
+
const noOp = () => { };
|
|
29
|
+
/**
|
|
30
|
+
* Creates a solution item.
|
|
31
|
+
*
|
|
32
|
+
* @param sourceId AGO id of group whose contents are to be added to solution or of an item to convert into a solution
|
|
33
|
+
* @param srcAuthentication Credentials for requests to source items
|
|
34
|
+
* @param destAuthentication Credentials for the requests to destination solution
|
|
35
|
+
* @param options Customizations for creating the solution
|
|
36
|
+
* @returns A promise that resolves with the AGO id of the new solution
|
|
37
|
+
*/
|
|
38
|
+
function createSolution(sourceId, srcAuthentication, destAuthentication, options) {
|
|
39
|
+
const createOptions = options || {};
|
|
40
|
+
const progressCb = createOptions.progressCallback || noOp;
|
|
41
|
+
createOptions.templateDictionary = Object.assign({}, createOptions.templateDictionary);
|
|
42
|
+
progressCb(1); // let the caller know that we've started
|
|
43
|
+
// Assume that source is a group and try to get group's information
|
|
44
|
+
return Promise.all([
|
|
45
|
+
(0, solution_common_1.getGroupBase)(sourceId, srcAuthentication),
|
|
46
|
+
(0, solution_common_1.getGroupContents)(sourceId, srcAuthentication),
|
|
47
|
+
(0, solution_common_1.getVelocityUrlBase)(srcAuthentication, createOptions.templateDictionary)
|
|
48
|
+
])
|
|
49
|
+
.then(
|
|
50
|
+
// Group fetches worked; assumption was correct
|
|
51
|
+
responses => {
|
|
52
|
+
createOptions.itemIds = responses[1];
|
|
53
|
+
progressCb(15);
|
|
54
|
+
return new Promise(resolve => {
|
|
55
|
+
// Update the createOptions with values from the group
|
|
56
|
+
resolve(_applySourceToCreateOptions(createOptions, responses[0], srcAuthentication, true));
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
// Assumption incorrect; try source as an item
|
|
60
|
+
() => {
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
createOptions.itemIds = [sourceId];
|
|
63
|
+
(0, solution_common_1.getItemBase)(sourceId, srcAuthentication).then(
|
|
64
|
+
// Update the createOptions with values from the item
|
|
65
|
+
itemBase => resolve(_applySourceToCreateOptions(createOptions, itemBase, srcAuthentication, false)), reject);
|
|
66
|
+
});
|
|
67
|
+
})
|
|
68
|
+
.then(createOptions => {
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
Promise.all([
|
|
71
|
+
(0, solution_common_1.getPortal)("", srcAuthentication),
|
|
72
|
+
(0, solution_common_1.getUser)(srcAuthentication)
|
|
73
|
+
]).then(responses => {
|
|
74
|
+
// check tracking
|
|
75
|
+
const [portalResponse, userResponse] = responses;
|
|
76
|
+
(0, solution_common_1.setLocationTrackingEnabled)(portalResponse, userResponse, createOptions.templateDictionary);
|
|
77
|
+
resolve(createOptions);
|
|
78
|
+
}, reject);
|
|
79
|
+
});
|
|
80
|
+
})
|
|
81
|
+
.then(
|
|
82
|
+
// Use a copy of the thumbnail rather than a URL to it
|
|
83
|
+
createOptions => {
|
|
84
|
+
return _addThumbnailFileToCreateOptions(createOptions, srcAuthentication);
|
|
85
|
+
})
|
|
86
|
+
.then(
|
|
87
|
+
// Create a solution
|
|
88
|
+
createOptions => {
|
|
89
|
+
return _createSolutionFromItemIds(createOptions, srcAuthentication, destAuthentication);
|
|
90
|
+
})
|
|
91
|
+
.then(
|
|
92
|
+
// Successfully created solution
|
|
93
|
+
createdSolutionId => {
|
|
94
|
+
progressCb(100); // finished
|
|
95
|
+
return createdSolutionId;
|
|
96
|
+
},
|
|
97
|
+
// Error fetching group, group contents, or item, or error creating solution from ids
|
|
98
|
+
error => {
|
|
99
|
+
progressCb(1);
|
|
100
|
+
console.error(error);
|
|
101
|
+
throw error;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
exports.createSolution = createSolution;
|
|
105
|
+
/**
|
|
106
|
+
* Update the createOptions with the group properties
|
|
107
|
+
*
|
|
108
|
+
* @param createOptions
|
|
109
|
+
* @param sourceInfo
|
|
110
|
+
* @param authentication
|
|
111
|
+
* @param isGroup Boolean to indicate if the files are associated with a group or item
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
function _applySourceToCreateOptions(createOptions, sourceInfo, srcAuthentication, isGroup = false) {
|
|
115
|
+
// Create a solution from the group's or item's contents,
|
|
116
|
+
// using the group's or item's information as defaults for the solution item
|
|
117
|
+
["title", "snippet", "description", "tags"].forEach(prop => {
|
|
118
|
+
createOptions[prop] = createOptions[prop] ?? sourceInfo[prop];
|
|
119
|
+
});
|
|
120
|
+
if (!createOptions.thumbnailurl && sourceInfo.thumbnail) {
|
|
121
|
+
// Get the full path to the thumbnail
|
|
122
|
+
createOptions.thumbnailurl = (0, solution_common_1.generateSourceThumbnailUrl)(srcAuthentication.portal, sourceInfo.id, sourceInfo.thumbnail, isGroup);
|
|
123
|
+
delete sourceInfo.thumbnail;
|
|
124
|
+
}
|
|
125
|
+
return createOptions;
|
|
126
|
+
}
|
|
127
|
+
exports._applySourceToCreateOptions = _applySourceToCreateOptions;
|
|
128
|
+
/**
|
|
129
|
+
* Update the createOptions with the thumbnail file
|
|
130
|
+
*
|
|
131
|
+
* @param createOptions
|
|
132
|
+
* @param srcAuthentication
|
|
133
|
+
* @private
|
|
134
|
+
*/
|
|
135
|
+
function _addThumbnailFileToCreateOptions(createOptions, srcAuthentication) {
|
|
136
|
+
return new Promise(resolve => {
|
|
137
|
+
if (!createOptions.thumbnail && createOptions.thumbnailurl) {
|
|
138
|
+
// Figure out the thumbnail's filename
|
|
139
|
+
const filename = (0, solution_common_1.getFilenameFromUrl)(createOptions.thumbnailurl) || "thumbnail";
|
|
140
|
+
const thumbnailurl = (0, solution_common_1.appendQueryParam)(createOptions.thumbnailurl, "w=400");
|
|
141
|
+
delete createOptions.thumbnailurl;
|
|
142
|
+
// Fetch the thumbnail
|
|
143
|
+
(0, solution_common_1.getBlobAsFile)(thumbnailurl, filename, srcAuthentication).then(thumbnail => {
|
|
144
|
+
createOptions.thumbnail = thumbnail;
|
|
145
|
+
resolve(createOptions);
|
|
146
|
+
}, () => {
|
|
147
|
+
resolve(createOptions);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
resolve(createOptions);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
exports._addThumbnailFileToCreateOptions = _addThumbnailFileToCreateOptions;
|
|
156
|
+
/**
|
|
157
|
+
* Creates a solution item using a list of AGO item ids.
|
|
158
|
+
*
|
|
159
|
+
* @param options Customizations for creating the solution
|
|
160
|
+
* @param srcAuthentication Credentials for requests to source items
|
|
161
|
+
* @param destAuthentication Credentials for the requests to destination solution
|
|
162
|
+
* @returns A promise that resolves with the AGO id of the new solution; solution item is deleted if its
|
|
163
|
+
* there is a problem updating it
|
|
164
|
+
* @private
|
|
165
|
+
*/
|
|
166
|
+
function _createSolutionFromItemIds(options, srcAuthentication, destAuthentication) {
|
|
167
|
+
let solutionId = "";
|
|
168
|
+
// Create a solution from the list of items
|
|
169
|
+
return _createSolutionItem(destAuthentication, options)
|
|
170
|
+
.then(id => {
|
|
171
|
+
solutionId = id;
|
|
172
|
+
// Add list of items to the new solution
|
|
173
|
+
return (0, add_content_to_solution_1.addContentToSolution)(solutionId, options, srcAuthentication, destAuthentication);
|
|
174
|
+
})
|
|
175
|
+
.catch(addError => {
|
|
176
|
+
// If the solution item got created, delete it
|
|
177
|
+
if (solutionId) {
|
|
178
|
+
const failSafeRemove = (0, hub_common_1.failSafe)(solution_common_1.removeItem, { success: true });
|
|
179
|
+
return failSafeRemove(solutionId, destAuthentication).then(() => {
|
|
180
|
+
throw addError;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
throw addError;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
exports._createSolutionFromItemIds = _createSolutionFromItemIds;
|
|
189
|
+
/**
|
|
190
|
+
* Creates an empty solution item.
|
|
191
|
+
*
|
|
192
|
+
* @param authentication Credentials for the request
|
|
193
|
+
* @param options Customizations for creating the solution
|
|
194
|
+
* @returns A promise that resolves with the AGO id of the new solution; solution item is deleted if its
|
|
195
|
+
* there is a problem updating its thumbnail
|
|
196
|
+
* @private
|
|
197
|
+
*/
|
|
198
|
+
function _createSolutionItem(authentication, options) {
|
|
199
|
+
const model = _createSolutionItemModel(options);
|
|
200
|
+
// Create new solution item
|
|
201
|
+
delete model.item.thumbnailurl;
|
|
202
|
+
model.item.thumbnail = options?.thumbnail;
|
|
203
|
+
return (0, solution_common_1.createItemWithData)(model.item, model.data, authentication, options?.folderId).then(createResponse => {
|
|
204
|
+
return Promise.resolve(createResponse.id);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
exports._createSolutionItem = _createSolutionItem;
|
|
208
|
+
/**
|
|
209
|
+
* Create the Solution Item model to be used to create
|
|
210
|
+
* the Solution Item itself
|
|
211
|
+
*
|
|
212
|
+
* @param options
|
|
213
|
+
* @private
|
|
214
|
+
*/
|
|
215
|
+
function _createSolutionItemModel(options) {
|
|
216
|
+
// Solution uses all supplied tags but for deploy.* tags; that information goes into properties
|
|
217
|
+
const creationTags = options?.tags ?? [];
|
|
218
|
+
const solutionItem = {
|
|
219
|
+
type: "Solution",
|
|
220
|
+
title: options?.title ?? (0, solution_common_1.createShortId)(),
|
|
221
|
+
snippet: options?.snippet ?? "",
|
|
222
|
+
description: options?.description ?? "",
|
|
223
|
+
properties: {
|
|
224
|
+
schemaVersion: solution_common_1.CURRENT_SCHEMA_VERSION
|
|
225
|
+
},
|
|
226
|
+
thumbnailurl: options?.thumbnailurl ?? "",
|
|
227
|
+
tags: creationTags.filter((tag) => !tag.startsWith("deploy.")),
|
|
228
|
+
typeKeywords: ["Solution", "Template"].concat(_getDeploymentProperties(creationTags))
|
|
229
|
+
};
|
|
230
|
+
// ensure that snippet and description are not nefarious
|
|
231
|
+
const sanitizedItem = (0, solution_common_1.sanitizeJSON)(solutionItem);
|
|
232
|
+
const addlKeywords = options?.additionalTypeKeywords || [];
|
|
233
|
+
sanitizedItem.typeKeywords = [].concat(solutionItem.typeKeywords, addlKeywords);
|
|
234
|
+
const solutionData = {
|
|
235
|
+
metadata: {},
|
|
236
|
+
templates: []
|
|
237
|
+
};
|
|
238
|
+
return {
|
|
239
|
+
item: sanitizedItem,
|
|
240
|
+
data: solutionData
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
exports._createSolutionItemModel = _createSolutionItemModel;
|
|
244
|
+
/**
|
|
245
|
+
* Gets the deploy.id and deploy.version tag values.
|
|
246
|
+
*
|
|
247
|
+
* @param tags A list of item tags
|
|
248
|
+
* @returns A list containing the two values found in the tags, or defaulting to a new GUID and "1.0", respectively,
|
|
249
|
+
* as needed
|
|
250
|
+
* @private
|
|
251
|
+
*/
|
|
252
|
+
function _getDeploymentProperties(tags) {
|
|
253
|
+
return [
|
|
254
|
+
"solutionid-" +
|
|
255
|
+
(_getDeploymentProperty("deploy.id.", tags) ?? (0, solution_common_1.createLongId)()),
|
|
256
|
+
"solutionversion-" +
|
|
257
|
+
(_getDeploymentProperty("deploy.version.", tags) ?? "1.0")
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
exports._getDeploymentProperties = _getDeploymentProperties;
|
|
261
|
+
/**
|
|
262
|
+
* Searches for a tag that has the specified prefix and returns the rest of the tag following that prefix.
|
|
263
|
+
*
|
|
264
|
+
* @param desiredTagPrefix Tag prefix to look for
|
|
265
|
+
* @param tags A list of item tags
|
|
266
|
+
* @returns The extracted value of the first matching tag or null if a tag with the specified prefix is not found
|
|
267
|
+
* @private
|
|
268
|
+
*/
|
|
269
|
+
function _getDeploymentProperty(desiredTagPrefix, tags) {
|
|
270
|
+
const foundTagAsList = tags.filter(tag => tag.startsWith(desiredTagPrefix));
|
|
271
|
+
if (foundTagAsList.length > 0) {
|
|
272
|
+
return foundTagAsList[0].substr(desiredTagPrefix.length);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
exports._getDeploymentProperty = _getDeploymentProperty;
|
|
279
279
|
//# sourceMappingURL=creator.js.map
|