@esri/solution-web-experience 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/esm/helpers/convert-web-experience-to-template.js +12 -7
  2. package/dist/esm/helpers/convert-web-experience-to-template.js.map +1 -1
  3. package/dist/esm/helpers/create-web-experience-model-from-template.js +1 -1
  4. package/dist/esm/helpers/create-web-experience-model-from-template.js.map +1 -1
  5. package/dist/esm/helpers/create-web-experience.js +27 -28
  6. package/dist/esm/helpers/create-web-experience.js.map +1 -1
  7. package/dist/esm/helpers/get-experience-subdomain.js +2 -2
  8. package/dist/esm/helpers/get-experience-subdomain.js.map +1 -1
  9. package/dist/esm/helpers/get-web-experience-dependencies.js +3 -3
  10. package/dist/esm/helpers/get-web-experience-dependencies.js.map +1 -1
  11. package/dist/esm/helpers/get-web-experience-url-template.js +5 -5
  12. package/dist/esm/helpers/get-web-experience-url-template.js.map +1 -1
  13. package/dist/esm/web-experience-processor.d.ts +15 -3
  14. package/dist/esm/web-experience-processor.js +31 -15
  15. package/dist/esm/web-experience-processor.js.map +1 -1
  16. package/dist/node/helpers/convert-web-experience-to-template.js +15 -10
  17. package/dist/node/helpers/convert-web-experience-to-template.js.map +1 -1
  18. package/dist/node/helpers/create-web-experience-model-from-template.js +3 -3
  19. package/dist/node/helpers/create-web-experience-model-from-template.js.map +1 -1
  20. package/dist/node/helpers/create-web-experience.js +28 -29
  21. package/dist/node/helpers/create-web-experience.js.map +1 -1
  22. package/dist/node/helpers/get-experience-subdomain.js +2 -2
  23. package/dist/node/helpers/get-experience-subdomain.js.map +1 -1
  24. package/dist/node/helpers/get-web-experience-dependencies.js +4 -4
  25. package/dist/node/helpers/get-web-experience-dependencies.js.map +1 -1
  26. package/dist/node/helpers/get-web-experience-url-template.js +6 -6
  27. package/dist/node/helpers/get-web-experience-url-template.js.map +1 -1
  28. package/dist/node/index.js +1 -1
  29. package/dist/node/index.js.map +1 -1
  30. package/dist/node/web-experience-processor.d.ts +15 -3
  31. package/dist/node/web-experience-processor.js +38 -21
  32. package/dist/node/web-experience-processor.js.map +1 -1
  33. package/dist/umd/web-experience-processor.d.ts +15 -3
  34. package/dist/umd/web-experience.umd.js +400 -404
  35. package/dist/umd/web-experience.umd.js.map +1 -1
  36. package/dist/umd/web-experience.umd.min.js +3 -3
  37. package/dist/umd/web-experience.umd.min.js.map +1 -1
  38. package/package.json +21 -21
@@ -1,7 +1,7 @@
1
1
  /* @preserve
2
- * @esri/solution-web-experience - v1.1.2 - Apache-2.0
2
+ * @esri/solution-web-experience - v1.2.0 - Apache-2.0
3
3
  * Copyright (c) 2018-2021 Esri, Inc.
4
- * Tue Aug 31 2021 00:02:40 GMT-0700 (Pacific Daylight Time)
4
+ * Thu Dec 09 2021 16:05:16 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,417 +16,413 @@
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/hub-common'), require('@esri/arcgis-rest-portal')) :
20
- typeof define === 'function' && define.amd ? define(['exports', '@esri/solution-common', '@esri/hub-common', '@esri/arcgis-rest-portal'], factory) :
21
- (global = global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution, global.arcgisHub, global.arcgisRest));
22
- }(this, (function (exports, solutionCommon, hubCommon, arcgisRestPortal) { 'use strict';
19
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/solution-common'), require('@esri/hub-common'), require('@esri/arcgis-rest-portal')) :
20
+ typeof define === 'function' && define.amd ? define(['exports', '@esri/solution-common', '@esri/hub-common', '@esri/arcgis-rest-portal'], factory) :
21
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution, global.arcgisHub, global.arcgisRest));
22
+ })(this, (function (exports, solutionCommon, hubCommon, arcgisRestPortal) { '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
- };
24
+ /**
25
+ * Returns the subdomain for an experience based on the api the session is
26
+ * authenticated against
27
+ *
28
+ * @param authentication UserSession
29
+ */
30
+ function getExperienceSubdomain(authentication) {
31
+ const portalUrl = authentication.portal || "https://www.arcgis.com/sharing/rest";
32
+ // TODO: Sort out how we locate experiences on portal?
33
+ let result;
34
+ if (portalUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
35
+ result = "experienceqa";
36
+ }
37
+ else if (portalUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
38
+ result = "experiencedev";
39
+ }
40
+ else if (portalUrl.match(/(www|\.maps)\.arcgis.com/)) {
41
+ result = "experience";
42
+ }
43
+ return result;
44
+ }
49
45
 
50
- /**
51
- * Returns the subdomain for an experience based on the api the session is
52
- * authenticated against
53
- *
54
- * @param authentication UserSession
55
- */
56
- function getExperienceSubdomain(authentication) {
57
- var portalUrl = authentication.portal || "https://www.arcgis.com/sharing/rest";
58
- // TODO: Sort out how we locate experiences on portal?
59
- var result;
60
- if (portalUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
61
- result = "experienceqa";
62
- }
63
- else if (portalUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
64
- result = "experiencedev";
65
- }
66
- else if (portalUrl.match(/(www|\.maps)\.arcgis.com/)) {
67
- result = "experience";
68
- }
69
- return result;
70
- }
46
+ /**
47
+ * For a given environment Prod/qa/dev/portal
48
+ * return the correct storymaps base url
49
+ *
50
+ * @param authentication
51
+ */
52
+ function getWebExperiencepUrlTemplate(authentication) {
53
+ let baseUrl = "";
54
+ const subdomain = getExperienceSubdomain(authentication);
55
+ if (subdomain) {
56
+ baseUrl = `https://${subdomain}.arcgis.com/experience/{{appid}}`;
57
+ }
58
+ else {
59
+ // we're on portal
60
+ // chop off the /sharing/rest to get the baseUrl
61
+ const portalBaseUrl = authentication.portal.replace("/sharing/rest", "");
62
+ baseUrl = `${portalBaseUrl}/apps/experiencebuilder/?id={{appid}}`;
63
+ }
64
+ return baseUrl;
65
+ }
71
66
 
72
- /**
73
- * For a given environment Prod/qa/dev/portal
74
- * return the correct storymaps base url
75
- *
76
- * @param authentication
77
- */
78
- function getWebExperiencepUrlTemplate(authentication) {
79
- var baseUrl = "";
80
- var subdomain = getExperienceSubdomain(authentication);
81
- if (subdomain) {
82
- baseUrl = "https://" + subdomain + ".arcgis.com/experience/{{appid}}";
83
- }
84
- else {
85
- // we're on portal
86
- // chop off the /sharing/rest to get the baseUrl
87
- var portalBaseUrl = authentication.portal.replace("/sharing/rest", "");
88
- baseUrl = portalBaseUrl + "/apps/experiencebuilder/?id={{appid}}";
89
- }
90
- return baseUrl;
91
- }
67
+ /** @license
68
+ * Copyright 2020 Esri
69
+ *
70
+ * Licensed under the Apache License, Version 2.0 (the "License");
71
+ * you may not use this file except in compliance with the License.
72
+ * You may obtain a copy of the License at
73
+ *
74
+ * http://www.apache.org/licenses/LICENSE-2.0
75
+ *
76
+ * Unless required by applicable law or agreed to in writing, software
77
+ * distributed under the License is distributed on an "AS IS" BASIS,
78
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
79
+ * See the License for the specific language governing permissions and
80
+ * limitations under the License.
81
+ */
82
+ /**
83
+ * Convert a Web Experience template into a Model that can be persisted to the Portal API
84
+ *
85
+ * @param templateModel Template
86
+ * @param settings Hash of values to interpolate into the template
87
+ * @param transforms Hash of transform functions to use in the interpolation
88
+ * @param authentication UserSession
89
+ */
90
+ function createWebExperienceModelFromTemplate(templateModel, settings, transforms, authentication) {
91
+ // get the experience base url
92
+ settings.experienceUrlTemplate = getWebExperiencepUrlTemplate(authentication);
93
+ const model = hubCommon.interpolate(templateModel, settings, transforms);
94
+ // ensure this is set - there may be some templates w/o `{{experienceTemplateUrl}}
95
+ model.item.url = settings.experienceUrlTemplate;
96
+ /* istanbul ignore else */
97
+ if (templateModel.item.thumbnail) {
98
+ model.item.thumbnail = templateModel.item.thumbnail; // interpolation trashes thumbnail binary
99
+ }
100
+ return Promise.resolve(model);
101
+ }
92
102
 
93
- /** @license
94
- * Copyright 2020 Esri
95
- *
96
- * Licensed under the Apache License, Version 2.0 (the "License");
97
- * you may not use this file except in compliance with the License.
98
- * You may obtain a copy of the License at
99
- *
100
- * http://www.apache.org/licenses/LICENSE-2.0
101
- *
102
- * Unless required by applicable law or agreed to in writing, software
103
- * distributed under the License is distributed on an "AS IS" BASIS,
104
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
105
- * See the License for the specific language governing permissions and
106
- * limitations under the License.
107
- */
108
- /**
109
- * Convert a Web Experience template into a Model that can be persisted to the Portal API
110
- *
111
- * @param templateModel Template
112
- * @param settings Hash of values to interpolate into the template
113
- * @param transforms Hash of transform functions to use in the interpolation
114
- * @param authentication UserSession
115
- */
116
- function createWebExperienceModelFromTemplate(templateModel, settings, transforms, authentication) {
117
- // get the experience base url
118
- settings.experienceUrlTemplate = getWebExperiencepUrlTemplate(authentication);
119
- var model = hubCommon.interpolate(templateModel, settings, transforms);
120
- // ensure this is set - there may be some templates w/o `{{experienceTemplateUrl}}
121
- model.item.url = settings.experienceUrlTemplate;
122
- /* istanbul ignore else */
123
- if (templateModel.item.thumbnail) {
124
- model.item.thumbnail = templateModel.item.thumbnail; // interpolation trashes thumbnail binary
125
- }
126
- return Promise.resolve(model);
127
- }
103
+ /** @license
104
+ * Copyright 2020 Esri
105
+ *
106
+ * Licensed under the Apache License, Version 2.0 (the "License");
107
+ * you may not use this file except in compliance with the License.
108
+ * You may obtain a copy of the License at
109
+ *
110
+ * http://www.apache.org/licenses/LICENSE-2.0
111
+ *
112
+ * Unless required by applicable law or agreed to in writing, software
113
+ * distributed under the License is distributed on an "AS IS" BASIS,
114
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
115
+ * See the License for the specific language governing permissions and
116
+ * limitations under the License.
117
+ */
118
+ /**
119
+ * Given a Model for a Web Experience, create the item in the Portal API
120
+ *
121
+ * @param model
122
+ * @param options
123
+ * @param authentication
124
+ */
125
+ function createWebExperience(model, folderId, options, authentication) {
126
+ const resources = [];
127
+ // For unkown reasons we can not seem to spy on createItemInFolder
128
+ // so we will create-then-move for now
129
+ const createOptions = {
130
+ // need to serialize
131
+ item: hubCommon.serializeModel(model),
132
+ authentication
133
+ };
134
+ /* istanbul ignore else */
135
+ if (model.item.thumbnail) {
136
+ createOptions.params = {
137
+ // Pass thumbnail file in via params because item property is serialized, which discards a blob
138
+ thumbnail: model.item.thumbnail
139
+ };
140
+ delete createOptions.item.thumbnail;
141
+ }
142
+ // Create the item
143
+ return (arcgisRestPortal.createItem(createOptions)
144
+ .then((createResponse) => {
145
+ model.item.id = createResponse.id;
146
+ const savedThumbnail = model.item.thumbnail;
147
+ model = hubCommon.interpolateItemId(model);
148
+ model.item.thumbnail = savedThumbnail; // interpolation trashes thumbnail binary
149
+ // Experiences store draft data in a resource attached to the item
150
+ // We'll just use the published data for the first "draft"
151
+ // changed from stringToBlob to objectToJsonBlob for issue #742
152
+ const draftResourceModel = hubCommon.cloneObject(model.data);
153
+ resources.push({
154
+ name: "config.json",
155
+ prefix: "config",
156
+ file: hubCommon.objectToJsonBlob(draftResourceModel)
157
+ });
158
+ // there may also be this image resources list
159
+ const imageListModel = hubCommon.cloneObject(model.properties.imageResourcesList);
160
+ if (imageListModel) {
161
+ resources.push({
162
+ name: "image-resources-list.json",
163
+ prefix: "images",
164
+ file: hubCommon.stringToBlob(JSON.stringify(imageListModel))
165
+ });
166
+ }
167
+ delete model.properties;
168
+ // update the experience with the newly interpolated model
169
+ const updateOptions = {
170
+ item: hubCommon.serializeModel(model),
171
+ authentication
172
+ };
173
+ if (model.item.thumbnail) {
174
+ updateOptions.params = {
175
+ // Pass thumbnail file in via params because item property is serialized, which discards a blob
176
+ thumbnail: model.item.thumbnail
177
+ };
178
+ delete updateOptions.item.thumbnail;
179
+ }
180
+ return Promise.all([
181
+ arcgisRestPortal.updateItem(updateOptions),
182
+ authentication.getUsername()
183
+ ]);
184
+ })
185
+ .then((responses) => {
186
+ const username = responses[1];
187
+ const failSafeAddItemResource = hubCommon.failSafe(arcgisRestPortal.addItemResource, {
188
+ success: true
189
+ });
190
+ // upload the data and oembed resources
191
+ const resourceUploadPromises = resources.map(resource => failSafeAddItemResource({
192
+ id: model.item.id,
193
+ owner: username,
194
+ resource: resource.file,
195
+ name: resource.name,
196
+ prefix: resource.prefix,
197
+ authentication
198
+ }));
199
+ // fire and forget
200
+ return Promise.all(resourceUploadPromises);
201
+ })
202
+ // .then(() => {
203
+ // // TODO: Can we leave this to the main process?
204
+ // return uploadResourcesFromUrl(model, options.assets || [], authentication);
205
+ // })
206
+ .then(() => {
207
+ // Move it
208
+ return arcgisRestPortal.moveItem({
209
+ itemId: model.item.id,
210
+ folderId,
211
+ authentication
212
+ });
213
+ })
214
+ .then(() => {
215
+ return model;
216
+ }));
217
+ }
128
218
 
129
- /** @license
130
- * Copyright 2020 Esri
131
- *
132
- * Licensed under the Apache License, Version 2.0 (the "License");
133
- * you may not use this file except in compliance with the License.
134
- * You may obtain a copy of the License at
135
- *
136
- * http://www.apache.org/licenses/LICENSE-2.0
137
- *
138
- * Unless required by applicable law or agreed to in writing, software
139
- * distributed under the License is distributed on an "AS IS" BASIS,
140
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141
- * See the License for the specific language governing permissions and
142
- * limitations under the License.
143
- */
144
- /**
145
- * Given a Model for a Web Experience, create the item in the Portal API
146
- *
147
- * @param model
148
- * @param options
149
- * @param authentication
150
- */
151
- function createWebExperience(model, folderId, options, authentication) {
152
- var resources = [];
153
- // For unkown reasons we can not seem to spy on createItemInFolder
154
- // so we will create-then-move for now
155
- var createOptions = {
156
- // need to serialize
157
- item: hubCommon.serializeModel(model),
158
- authentication: authentication
159
- };
160
- /* istanbul ignore else */
161
- if (model.item.thumbnail) {
162
- createOptions.params = {
163
- // Pass thumbnail file in via params because item property is serialized, which discards a blob
164
- thumbnail: model.item.thumbnail
165
- };
166
- delete createOptions.item.thumbnail;
167
- }
168
- // Create the item
169
- return (arcgisRestPortal.createItem(createOptions)
170
- .then(function (createResponse) {
171
- model.item.id = createResponse.id;
172
- var savedThumbnail = model.item.thumbnail;
173
- model = hubCommon.interpolateItemId(model);
174
- model.item.thumbnail = savedThumbnail; // interpolation trashes thumbnail binary
175
- // Experiences store draft data in a resource attached to the item
176
- // We'll just use the published data for the first "draft"
177
- var draftResourceModel = hubCommon.cloneObject(model.data);
178
- resources.push({
179
- name: "config.json",
180
- prefix: "config",
181
- file: hubCommon.stringToBlob(JSON.stringify(draftResourceModel))
182
- });
183
- // there may also be this image resources list
184
- var imageListModel = hubCommon.cloneObject(model.properties.imageResourcesList);
185
- if (imageListModel) {
186
- resources.push({
187
- name: "image-resources-list.json",
188
- prefix: "images",
189
- file: hubCommon.stringToBlob(JSON.stringify(imageListModel))
190
- });
191
- }
192
- delete model.properties;
193
- // update the experience with the newly interpolated model
194
- var updateOptions = {
195
- item: hubCommon.serializeModel(model),
196
- authentication: authentication
197
- };
198
- if (model.item.thumbnail) {
199
- updateOptions.params = {
200
- // Pass thumbnail file in via params because item property is serialized, which discards a blob
201
- thumbnail: model.item.thumbnail
202
- };
203
- delete updateOptions.item.thumbnail;
204
- }
205
- return Promise.all([
206
- arcgisRestPortal.updateItem(updateOptions),
207
- authentication.getUsername()
208
- ]);
209
- })
210
- .then(function (responses) {
211
- var username = responses[1];
212
- var failSafeAddItemResource = hubCommon.failSafe(arcgisRestPortal.addItemResource, {
213
- success: true
214
- });
215
- // upload the data and oembed resources
216
- var resourceUploadPromises = resources.map(function (resource) {
217
- return failSafeAddItemResource({
218
- id: model.item.id,
219
- owner: username,
220
- resource: resource.file,
221
- name: resource.name,
222
- prefix: resource.prefix,
223
- authentication: authentication
224
- });
225
- });
226
- // fire and forget
227
- return Promise.all(resourceUploadPromises);
228
- })
229
- // .then(() => {
230
- // // TODO: Can we leave this to the main process?
231
- // return uploadResourcesFromUrl(model, options.assets || [], authentication);
232
- // })
233
- .then(function () {
234
- // Move it
235
- return arcgisRestPortal.moveItem({
236
- itemId: model.item.id,
237
- folderId: folderId,
238
- authentication: authentication
239
- });
240
- })
241
- .then(function () {
242
- return model;
243
- }));
244
- }
219
+ /** @license
220
+ * Copyright 2020 Esri
221
+ *
222
+ * Licensed under the Apache License, Version 2.0 (the "License");
223
+ * you may not use this file except in compliance with the License.
224
+ * You may obtain a copy of the License at
225
+ *
226
+ * http://www.apache.org/licenses/LICENSE-2.0
227
+ *
228
+ * Unless required by applicable law or agreed to in writing, software
229
+ * distributed under the License is distributed on an "AS IS" BASIS,
230
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
231
+ * See the License for the specific language governing permissions and
232
+ * limitations under the License.
233
+ */
234
+ /**
235
+ * Given an Web Experience model, extract out all the
236
+ * items it depends on from the `dataSources` hash
237
+ *
238
+ * @param model IModel
239
+ */
240
+ function getWebExperienceDependencies(model) {
241
+ const dataSources = hubCommon.getProp(model, "data.dataSources") || {};
242
+ return Object.keys(dataSources).reduce((acc, key) => {
243
+ return hubCommon.maybePush(hubCommon.getProp(dataSources, `${key}.itemId`), acc);
244
+ }, []);
245
+ }
245
246
 
246
- /** @license
247
- * Copyright 2020 Esri
248
- *
249
- * Licensed under the Apache License, Version 2.0 (the "License");
250
- * you may not use this file except in compliance with the License.
251
- * You may obtain a copy of the License at
252
- *
253
- * http://www.apache.org/licenses/LICENSE-2.0
254
- *
255
- * Unless required by applicable law or agreed to in writing, software
256
- * distributed under the License is distributed on an "AS IS" BASIS,
257
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
258
- * See the License for the specific language governing permissions and
259
- * limitations under the License.
260
- */
261
- /**
262
- * Given an Web Experience model, extract out all the
263
- * items it depends on from the `dataSources` hash
264
- *
265
- * @param model IModel
266
- */
267
- function getWebExperienceDependencies(model) {
268
- var dataSources = hubCommon.getProp(model, "data.dataSources") || {};
269
- return Object.keys(dataSources).reduce(function (acc, key) {
270
- return hubCommon.maybePush(hubCommon.getProp(dataSources, key + ".itemId"), acc);
271
- }, []);
272
- }
247
+ /** @license
248
+ * Copyright 2020 Esri
249
+ *
250
+ * Licensed under the Apache License, Version 2.0 (the "License");
251
+ * you may not use this file except in compliance with the License.
252
+ * You may obtain a copy of the License at
253
+ *
254
+ * http://www.apache.org/licenses/LICENSE-2.0
255
+ *
256
+ * Unless required by applicable law or agreed to in writing, software
257
+ * distributed under the License is distributed on an "AS IS" BASIS,
258
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
259
+ * See the License for the specific language governing permissions and
260
+ * limitations under the License.
261
+ */
262
+ /**
263
+ * Convert an Experience item into a template
264
+ *
265
+ * Pretty simpler conversion - remove extra item props, extract out
266
+ * items from the data.dataSources hash.
267
+ *
268
+ * @param model
269
+ * @param authentication
270
+ */
271
+ function convertWebExperienceToTemplate(model) {
272
+ const tmpl = solutionCommon.createPlaceholderTemplate(model.item.id, model.item.type);
273
+ tmpl.key = `${hubCommon.propifyString(model.item.title)}_${hubCommon.createId("i")}`;
274
+ const clone = hubCommon.cloneObject(model);
275
+ tmpl.data = clone.data;
276
+ // We need to save these properties in order to restore them after hub.js deletes them
277
+ const created = clone.item.created;
278
+ const modified = clone.item.modified;
279
+ tmpl.item = hubCommon.normalizeSolutionTemplateItem(clone.item);
280
+ tmpl.item.created = created;
281
+ tmpl.item.modified = modified;
282
+ // templatize the url. This is updated during the createModelFromTemplate phase
283
+ // of the deployment process
284
+ tmpl.item.url = "{{experienceUrlTemplate}}";
285
+ // use typeKeyword to mark item as published (we decided to discard unpublished drafts)
286
+ const typeKeywords = tmpl.item.typeKeywords;
287
+ if (typeKeywords.indexOf(changedTypeKW) !== -1) {
288
+ tmpl.item.typeKeywords = [publishedTypeKW].concat(tmpl.item.typeKeywords.filter(word => word !== changedTypeKW));
289
+ }
290
+ tmpl.dependencies = getWebExperienceDependencies(model);
291
+ return Promise.resolve(tmpl);
292
+ // TODO: For now, we let the generic process handle item resources
293
+ // However, many newer item types have complex type-specific resource handling
294
+ // requirements so this code may be useful in the future
295
+ // ------------------------------------------------------
296
+ // return getItemResources(tmpl.itemId, authentication)
297
+ // .then((response) => {
298
+ // tmpl.resources = response.resources.map(e => e.resource)
299
+ // // Discard draft version
300
+ // .filter(filename => filename !== 'config.json');
301
+ // return tmpl;
302
+ // });
303
+ }
304
+ const publishedTypeKW = "status: Published";
305
+ const changedTypeKW = "status: Changed";
273
306
 
274
- /** @license
275
- * Copyright 2020 Esri
276
- *
277
- * Licensed under the Apache License, Version 2.0 (the "License");
278
- * you may not use this file except in compliance with the License.
279
- * You may obtain a copy of the License at
280
- *
281
- * http://www.apache.org/licenses/LICENSE-2.0
282
- *
283
- * Unless required by applicable law or agreed to in writing, software
284
- * distributed under the License is distributed on an "AS IS" BASIS,
285
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286
- * See the License for the specific language governing permissions and
287
- * limitations under the License.
288
- */
289
- /**
290
- * Convert an Experience item into a template
291
- *
292
- * Pretty simpler conversion - remove extra item props, extract out
293
- * items from the data.dataSources hash.
294
- *
295
- * @param model
296
- * @param authentication
297
- */
298
- function convertWebExperienceToTemplate(model) {
299
- var tmpl = solutionCommon.createPlaceholderTemplate(model.item.id, model.item.type);
300
- tmpl.key = hubCommon.propifyString(model.item.title) + "_" + hubCommon.createId("i");
301
- var clone = hubCommon.cloneObject(model);
302
- tmpl.data = clone.data;
303
- tmpl.item = hubCommon.normalizeSolutionTemplateItem(clone.item);
304
- // templatize the url. This is updated during the createModelFromTemplate phase
305
- // of the deployment process
306
- tmpl.item.url = "{{experienceUrlTemplate}}";
307
- // use typeKeyword to mark item as published (we decided to discard unpublished drafts)
308
- var typeKeywords = tmpl.item.typeKeywords;
309
- if (typeKeywords.indexOf(changedTypeKW) !== -1) {
310
- tmpl.item.typeKeywords = [publishedTypeKW].concat(tmpl.item.typeKeywords.filter(function (word) { return word !== changedTypeKW; }));
311
- }
312
- tmpl.dependencies = getWebExperienceDependencies(model);
313
- return Promise.resolve(tmpl);
314
- // TODO: For now, we let the generic process handle item resources
315
- // However, many newer item types have complex type-specific resource handling
316
- // requirements so this code may be useful in the future
317
- // ------------------------------------------------------
318
- // return getItemResources(tmpl.itemId, authentication)
319
- // .then((response) => {
320
- // tmpl.resources = response.resources.map(e => e.resource)
321
- // // Discard draft version
322
- // .filter(filename => filename !== 'config.json');
323
- // return tmpl;
324
- // });
325
- }
326
- var publishedTypeKW = "status: Published";
327
- var changedTypeKW = "status: Changed";
307
+ /** @license
308
+ * Copyright 2018 Esri
309
+ *
310
+ * Licensed under the Apache License, Version 2.0 (the "License");
311
+ * you may not use this file except in compliance with the License.
312
+ * You may obtain a copy of the License at
313
+ *
314
+ * http://www.apache.org/licenses/LICENSE-2.0
315
+ *
316
+ * Unless required by applicable law or agreed to in writing, software
317
+ * distributed under the License is distributed on an "AS IS" BASIS,
318
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
319
+ * See the License for the specific language governing permissions and
320
+ * limitations under the License.
321
+ */
322
+ /**
323
+ * Convert a Web Experience item into a Template
324
+ *
325
+ * @param solutionItemId
326
+ * @param itemInfo
327
+ * @param destAuthentication Credentials for requests to the destination organization
328
+ * @param srcAuthentication Credentials for requests to source items
329
+ * @param isGroup
330
+ */
331
+ function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication) {
332
+ // use the itemInfo to setup a model
333
+ const model = {
334
+ item: itemInfo,
335
+ data: {}
336
+ };
337
+ // fetch the data.json
338
+ return arcgisRestPortal.getItemData(itemInfo.id, { authentication: srcAuthentication }).then(data => {
339
+ // append into the model
340
+ model.data = data;
341
+ // and use that to create a template
342
+ return convertWebExperienceToTemplate(model);
343
+ });
344
+ }
345
+ /**
346
+ * Create a Web Experience from a Template
347
+ *
348
+ * @param template
349
+ * @param templateDictionary
350
+ * @param destinationAuthentication
351
+ * @param itemProgressCallback
352
+ */
353
+ function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
354
+ // let the progress system know we've started...
355
+ const startStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Started, 0);
356
+ // and if it returned false, just resolve out
357
+ if (!startStatus) {
358
+ return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
359
+ }
360
+ let exbModel;
361
+ return createWebExperienceModelFromTemplate(template, templateDictionary, {}, destinationAuthentication)
362
+ .then(model => {
363
+ exbModel = model;
364
+ return createWebExperience(model, templateDictionary.folderId, {}, destinationAuthentication);
365
+ })
366
+ .then(createdModel => {
367
+ exbModel.item.id = createdModel.item.id;
368
+ exbModel.item.url = createdModel.item.url;
369
+ // Update the template dictionary
370
+ // TODO: This should be done in whatever recieves
371
+ // the outcome of this promise chain
372
+ templateDictionary[template.itemId] = {
373
+ itemId: createdModel.item.id
374
+ };
375
+ const finalStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor || 2, createdModel.item.id);
376
+ if (!finalStatus) {
377
+ // clean up the site we just created
378
+ const failSafeRemove = hubCommon.failSafe(arcgisRestPortal.removeItem, { success: true });
379
+ return failSafeRemove({
380
+ id: exbModel.item.id,
381
+ authentication: destinationAuthentication
382
+ }).then(() => {
383
+ return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
384
+ });
385
+ }
386
+ else {
387
+ // finally, return ICreateItemFromTemplateResponse
388
+ const response = {
389
+ item: {
390
+ ...template,
391
+ ...exbModel
392
+ },
393
+ id: exbModel.item.id,
394
+ type: template.type,
395
+ postProcess: false
396
+ };
397
+ response.item.itemId = exbModel.item.id;
398
+ return response;
399
+ }
400
+ });
401
+ }
402
+ /**
403
+ * Post-Process an Experience
404
+ *
405
+ * @param {string} itemId The item ID
406
+ * @param {string} type The template type
407
+ * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects
408
+ * @param {any} templateDictionary The template dictionary
409
+ * @param {UserSession} authentication The destination session info
410
+ * @returns Promise resolving to successfulness of update
411
+ */
412
+ function postProcess(itemId, type, itemInfos, template, templates, templateDictionary, authentication) {
413
+ return solutionCommon.updateItemTemplateFromDictionary(itemId, templateDictionary, authentication);
414
+ }
328
415
 
329
- /** @license
330
- * Copyright 2018 Esri
331
- *
332
- * Licensed under the Apache License, Version 2.0 (the "License");
333
- * you may not use this file except in compliance with the License.
334
- * You may obtain a copy of the License at
335
- *
336
- * http://www.apache.org/licenses/LICENSE-2.0
337
- *
338
- * Unless required by applicable law or agreed to in writing, software
339
- * distributed under the License is distributed on an "AS IS" BASIS,
340
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
341
- * See the License for the specific language governing permissions and
342
- * limitations under the License.
343
- */
344
- /**
345
- * Convert a Web Experience item into a Template
346
- *
347
- * @param solutionItemId
348
- * @param itemInfo
349
- * @param authentication
350
- * @param isGroup
351
- */
352
- function convertItemToTemplate(solutionItemId, itemInfo, authentication) {
353
- // use the itemInfo to setup a model
354
- var model = {
355
- item: itemInfo,
356
- data: {}
357
- };
358
- // fetch the data.json
359
- return arcgisRestPortal.getItemData(itemInfo.id, { authentication: authentication }).then(function (data) {
360
- // append into the model
361
- model.data = data;
362
- // and use that to create a template
363
- return convertWebExperienceToTemplate(model);
364
- });
365
- }
366
- /**
367
- * Create a Web Experience from a Template
368
- *
369
- * @param template
370
- * @param templateDictionary
371
- * @param destinationAuthentication
372
- * @param itemProgressCallback
373
- */
374
- function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
375
- // let the progress system know we've started...
376
- var startStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Started, 0);
377
- // and if it returned false, just resolve out
378
- if (!startStatus) {
379
- return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
380
- }
381
- var exbModel;
382
- return createWebExperienceModelFromTemplate(template, templateDictionary, {}, destinationAuthentication)
383
- .then(function (model) {
384
- exbModel = model;
385
- return createWebExperience(model, templateDictionary.folderId, {}, destinationAuthentication);
386
- })
387
- .then(function (createdModel) {
388
- exbModel.item.id = createdModel.item.id;
389
- exbModel.item.url = createdModel.item.url;
390
- // Update the template dictionary
391
- // TODO: This should be done in whatever recieves
392
- // the outcome of this promise chain
393
- templateDictionary[template.itemId] = {
394
- itemId: createdModel.item.id
395
- };
396
- var finalStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor || 2, createdModel.item.id);
397
- if (!finalStatus) {
398
- // clean up the site we just created
399
- var failSafeRemove = hubCommon.failSafe(arcgisRestPortal.removeItem, { success: true });
400
- return failSafeRemove({
401
- id: exbModel.item.id,
402
- authentication: destinationAuthentication
403
- }).then(function () {
404
- return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
405
- });
406
- }
407
- else {
408
- // finally, return ICreateItemFromTemplateResponse
409
- var response = {
410
- item: __assign(__assign({}, template), exbModel),
411
- id: exbModel.item.id,
412
- type: template.type,
413
- postProcess: false
414
- };
415
- response.item.itemId = exbModel.item.id;
416
- return response;
417
- }
418
- });
419
- }
416
+ var webExperienceProcessor = /*#__PURE__*/Object.freeze({
417
+ __proto__: null,
418
+ convertItemToTemplate: convertItemToTemplate,
419
+ createItemFromTemplate: createItemFromTemplate,
420
+ postProcess: postProcess
421
+ });
420
422
 
421
- var webExperienceProcessor = /*#__PURE__*/Object.freeze({
422
- __proto__: null,
423
- convertItemToTemplate: convertItemToTemplate,
424
- createItemFromTemplate: createItemFromTemplate
425
- });
423
+ exports.WebExperienceProcessor = webExperienceProcessor;
426
424
 
427
- exports.WebExperienceProcessor = webExperienceProcessor;
425
+ Object.defineProperty(exports, '__esModule', { value: true });
428
426
 
429
- Object.defineProperty(exports, '__esModule', { value: true });
430
-
431
- })));
427
+ }));
432
428
  //# sourceMappingURL=web-experience.umd.js.map