@esri/solution-web-experience 0.24.0 → 1.1.4

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 +7 -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 +24 -26
  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 +12 -1
  14. package/dist/esm/web-experience-processor.js +28 -13
  15. package/dist/esm/web-experience-processor.js.map +1 -1
  16. package/dist/node/helpers/convert-web-experience-to-template.js +12 -12
  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 +4 -4
  19. package/dist/node/helpers/create-web-experience-model-from-template.js.map +1 -1
  20. package/dist/node/helpers/create-web-experience.js +34 -36
  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 +12 -1
  31. package/dist/node/web-experience-processor.js +40 -24
  32. package/dist/node/web-experience-processor.js.map +1 -1
  33. package/dist/umd/web-experience-processor.d.ts +12 -1
  34. package/dist/umd/web-experience.umd.js +391 -402
  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 +19 -19
@@ -1,7 +1,7 @@
1
1
  /* @preserve
2
- * @esri/solution-web-experience - v0.24.0 - Apache-2.0
2
+ * @esri/solution-web-experience - v1.1.4 - Apache-2.0
3
3
  * Copyright (c) 2018-2021 Esri, Inc.
4
- * Wed Jun 09 2021 15:02:27 GMT-0700 (Pacific Daylight Time)
4
+ * Tue Oct 26 2021 15:16:00 GMT-0700 (Pacific Daylight 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,406 @@
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));
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
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
+ const draftResourceModel = hubCommon.cloneObject(model.data);
152
+ resources.push({
153
+ name: "config.json",
154
+ prefix: "config",
155
+ file: hubCommon.stringToBlob(JSON.stringify(draftResourceModel))
156
+ });
157
+ // there may also be this image resources list
158
+ const imageListModel = hubCommon.cloneObject(model.properties.imageResourcesList);
159
+ if (imageListModel) {
160
+ resources.push({
161
+ name: "image-resources-list.json",
162
+ prefix: "images",
163
+ file: hubCommon.stringToBlob(JSON.stringify(imageListModel))
164
+ });
165
+ }
166
+ delete model.properties;
167
+ // update the experience with the newly interpolated model
168
+ const updateOptions = {
169
+ item: hubCommon.serializeModel(model),
170
+ authentication
171
+ };
172
+ if (model.item.thumbnail) {
173
+ updateOptions.params = {
174
+ // Pass thumbnail file in via params because item property is serialized, which discards a blob
175
+ thumbnail: model.item.thumbnail
176
+ };
177
+ delete updateOptions.item.thumbnail;
178
+ }
179
+ return Promise.all([
180
+ arcgisRestPortal.updateItem(updateOptions),
181
+ authentication.getUsername()
182
+ ]);
183
+ })
184
+ .then((responses) => {
185
+ const username = responses[1];
186
+ const failSafeAddItemResource = hubCommon.failSafe(arcgisRestPortal.addItemResource, {
187
+ success: true
188
+ });
189
+ // upload the data and oembed resources
190
+ const resourceUploadPromises = resources.map(resource => failSafeAddItemResource({
191
+ id: model.item.id,
192
+ owner: username,
193
+ resource: resource.file,
194
+ name: resource.name,
195
+ prefix: resource.prefix,
196
+ authentication
197
+ }));
198
+ // fire and forget
199
+ return Promise.all(resourceUploadPromises);
200
+ })
201
+ // .then(() => {
202
+ // // TODO: Can we leave this to the main process?
203
+ // return uploadResourcesFromUrl(model, options.assets || [], authentication);
204
+ // })
205
+ .then(() => {
206
+ // Move it
207
+ return arcgisRestPortal.moveItem({
208
+ itemId: model.item.id,
209
+ folderId,
210
+ authentication
211
+ });
212
+ })
213
+ .then(() => {
214
+ return model;
215
+ }));
216
+ }
128
217
 
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
- }
218
+ /** @license
219
+ * Copyright 2020 Esri
220
+ *
221
+ * Licensed under the Apache License, Version 2.0 (the "License");
222
+ * you may not use this file except in compliance with the License.
223
+ * You may obtain a copy of the License at
224
+ *
225
+ * http://www.apache.org/licenses/LICENSE-2.0
226
+ *
227
+ * Unless required by applicable law or agreed to in writing, software
228
+ * distributed under the License is distributed on an "AS IS" BASIS,
229
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
230
+ * See the License for the specific language governing permissions and
231
+ * limitations under the License.
232
+ */
233
+ /**
234
+ * Given an Web Experience model, extract out all the
235
+ * items it depends on from the `dataSources` hash
236
+ *
237
+ * @param model IModel
238
+ */
239
+ function getWebExperienceDependencies(model) {
240
+ const dataSources = hubCommon.getProp(model, "data.dataSources") || {};
241
+ return Object.keys(dataSources).reduce((acc, key) => {
242
+ return hubCommon.maybePush(hubCommon.getProp(dataSources, `${key}.itemId`), acc);
243
+ }, []);
244
+ }
245
245
 
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
- }
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
+ * Convert an Experience item into a template
263
+ *
264
+ * Pretty simpler conversion - remove extra item props, extract out
265
+ * items from the data.dataSources hash.
266
+ *
267
+ * @param model
268
+ * @param authentication
269
+ */
270
+ function convertWebExperienceToTemplate(model) {
271
+ const tmpl = solutionCommon.createPlaceholderTemplate(model.item.id, model.item.type);
272
+ tmpl.key = `${hubCommon.propifyString(model.item.title)}_${hubCommon.createId("i")}`;
273
+ const clone = hubCommon.cloneObject(model);
274
+ tmpl.data = clone.data;
275
+ tmpl.item = hubCommon.normalizeSolutionTemplateItem(clone.item);
276
+ // templatize the url. This is updated during the createModelFromTemplate phase
277
+ // of the deployment process
278
+ tmpl.item.url = "{{experienceUrlTemplate}}";
279
+ // use typeKeyword to mark item as published (we decided to discard unpublished drafts)
280
+ const typeKeywords = tmpl.item.typeKeywords;
281
+ if (typeKeywords.indexOf(changedTypeKW) !== -1) {
282
+ tmpl.item.typeKeywords = [publishedTypeKW].concat(tmpl.item.typeKeywords.filter(word => word !== changedTypeKW));
283
+ }
284
+ tmpl.dependencies = getWebExperienceDependencies(model);
285
+ return Promise.resolve(tmpl);
286
+ // TODO: For now, we let the generic process handle item resources
287
+ // However, many newer item types have complex type-specific resource handling
288
+ // requirements so this code may be useful in the future
289
+ // ------------------------------------------------------
290
+ // return getItemResources(tmpl.itemId, authentication)
291
+ // .then((response) => {
292
+ // tmpl.resources = response.resources.map(e => e.resource)
293
+ // // Discard draft version
294
+ // .filter(filename => filename !== 'config.json');
295
+ // return tmpl;
296
+ // });
297
+ }
298
+ const publishedTypeKW = "status: Published";
299
+ const changedTypeKW = "status: Changed";
273
300
 
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";
301
+ /** @license
302
+ * Copyright 2018 Esri
303
+ *
304
+ * Licensed under the Apache License, Version 2.0 (the "License");
305
+ * you may not use this file except in compliance with the License.
306
+ * You may obtain a copy of the License at
307
+ *
308
+ * http://www.apache.org/licenses/LICENSE-2.0
309
+ *
310
+ * Unless required by applicable law or agreed to in writing, software
311
+ * distributed under the License is distributed on an "AS IS" BASIS,
312
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
313
+ * See the License for the specific language governing permissions and
314
+ * limitations under the License.
315
+ */
316
+ /**
317
+ * Convert a Web Experience item into a Template
318
+ *
319
+ * @param solutionItemId
320
+ * @param itemInfo
321
+ * @param authentication
322
+ * @param isGroup
323
+ */
324
+ function convertItemToTemplate(solutionItemId, itemInfo, authentication) {
325
+ // use the itemInfo to setup a model
326
+ const model = {
327
+ item: itemInfo,
328
+ data: {}
329
+ };
330
+ // fetch the data.json
331
+ return arcgisRestPortal.getItemData(itemInfo.id, { authentication }).then(data => {
332
+ // append into the model
333
+ model.data = data;
334
+ // and use that to create a template
335
+ return convertWebExperienceToTemplate(model);
336
+ });
337
+ }
338
+ /**
339
+ * Create a Web Experience from a Template
340
+ *
341
+ * @param template
342
+ * @param templateDictionary
343
+ * @param destinationAuthentication
344
+ * @param itemProgressCallback
345
+ */
346
+ function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
347
+ // let the progress system know we've started...
348
+ const startStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Started, 0);
349
+ // and if it returned false, just resolve out
350
+ if (!startStatus) {
351
+ return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
352
+ }
353
+ let exbModel;
354
+ return createWebExperienceModelFromTemplate(template, templateDictionary, {}, destinationAuthentication)
355
+ .then(model => {
356
+ exbModel = model;
357
+ return createWebExperience(model, templateDictionary.folderId, {}, destinationAuthentication);
358
+ })
359
+ .then(createdModel => {
360
+ exbModel.item.id = createdModel.item.id;
361
+ exbModel.item.url = createdModel.item.url;
362
+ // Update the template dictionary
363
+ // TODO: This should be done in whatever recieves
364
+ // the outcome of this promise chain
365
+ templateDictionary[template.itemId] = {
366
+ itemId: createdModel.item.id
367
+ };
368
+ const finalStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor || 2, createdModel.item.id);
369
+ if (!finalStatus) {
370
+ // clean up the site we just created
371
+ const failSafeRemove = hubCommon.failSafe(arcgisRestPortal.removeItem, { success: true });
372
+ return failSafeRemove({
373
+ id: exbModel.item.id,
374
+ authentication: destinationAuthentication
375
+ }).then(() => {
376
+ return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
377
+ });
378
+ }
379
+ else {
380
+ // finally, return ICreateItemFromTemplateResponse
381
+ const response = {
382
+ item: {
383
+ ...template,
384
+ ...exbModel
385
+ },
386
+ id: exbModel.item.id,
387
+ type: template.type,
388
+ postProcess: false
389
+ };
390
+ response.item.itemId = exbModel.item.id;
391
+ return response;
392
+ }
393
+ });
394
+ }
395
+ /**
396
+ * Post-Process an Experience
397
+ *
398
+ * @param {string} itemId The item ID
399
+ * @param {string} type The template type
400
+ * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects
401
+ * @param {any} templateDictionary The template dictionary
402
+ * @param {UserSession} authentication The destination session info
403
+ * @returns Promise resolving to successfulness of update
404
+ */
405
+ function postProcess(itemId, type, itemInfos, template, templates, templateDictionary, authentication) {
406
+ return solutionCommon.updateItemTemplateFromDictionary(itemId, templateDictionary, authentication);
407
+ }
328
408
 
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
- }
409
+ var webExperienceProcessor = /*#__PURE__*/Object.freeze({
410
+ __proto__: null,
411
+ convertItemToTemplate: convertItemToTemplate,
412
+ createItemFromTemplate: createItemFromTemplate,
413
+ postProcess: postProcess
414
+ });
420
415
 
421
- var webExperienceProcessor = /*#__PURE__*/Object.freeze({
422
- __proto__: null,
423
- convertItemToTemplate: convertItemToTemplate,
424
- createItemFromTemplate: createItemFromTemplate
425
- });
416
+ exports.WebExperienceProcessor = webExperienceProcessor;
426
417
 
427
- exports.WebExperienceProcessor = webExperienceProcessor;
428
-
429
- Object.defineProperty(exports, '__esModule', { value: true });
418
+ Object.defineProperty(exports, '__esModule', { value: true });
430
419
 
431
420
  })));
432
421
  //# sourceMappingURL=web-experience.umd.js.map