@esri/solution-web-experience 3.0.0 → 3.1.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 (37) hide show
  1. package/package.json +5 -5
  2. package/dist/node/helpers/convert-web-experience-to-template.d.ts +0 -27
  3. package/dist/node/helpers/convert-web-experience-to-template.js +0 -67
  4. package/dist/node/helpers/convert-web-experience-to-template.js.map +0 -1
  5. package/dist/node/helpers/create-web-experience-model-from-template.d.ts +0 -26
  6. package/dist/node/helpers/create-web-experience-model-from-template.js +0 -42
  7. package/dist/node/helpers/create-web-experience-model-from-template.js.map +0 -1
  8. package/dist/node/helpers/create-web-experience.d.ts +0 -25
  9. package/dist/node/helpers/create-web-experience.js +0 -122
  10. package/dist/node/helpers/create-web-experience.js.map +0 -1
  11. package/dist/node/helpers/get-experience-subdomain.d.ts +0 -23
  12. package/dist/node/helpers/get-experience-subdomain.js +0 -26
  13. package/dist/node/helpers/get-experience-subdomain.js.map +0 -1
  14. package/dist/node/helpers/get-web-experience-dependencies.d.ts +0 -23
  15. package/dist/node/helpers/get-web-experience-dependencies.js +0 -33
  16. package/dist/node/helpers/get-web-experience-dependencies.js.map +0 -1
  17. package/dist/node/helpers/get-web-experience-url-template.d.ts +0 -23
  18. package/dist/node/helpers/get-web-experience-url-template.js +0 -26
  19. package/dist/node/helpers/get-web-experience-url-template.js.map +0 -1
  20. package/dist/node/index.d.ts +0 -17
  21. package/dist/node/index.js +0 -22
  22. package/dist/node/index.js.map +0 -1
  23. package/dist/node/web-experience-processor.d.ts +0 -51
  24. package/dist/node/web-experience-processor.js +0 -126
  25. package/dist/node/web-experience-processor.js.map +0 -1
  26. package/dist/umd/web-experience/src/helpers/convert-web-experience-to-template.d.ts +0 -27
  27. package/dist/umd/web-experience/src/helpers/create-web-experience-model-from-template.d.ts +0 -26
  28. package/dist/umd/web-experience/src/helpers/create-web-experience.d.ts +0 -25
  29. package/dist/umd/web-experience/src/helpers/get-experience-subdomain.d.ts +0 -23
  30. package/dist/umd/web-experience/src/helpers/get-web-experience-dependencies.d.ts +0 -23
  31. package/dist/umd/web-experience/src/helpers/get-web-experience-url-template.d.ts +0 -23
  32. package/dist/umd/web-experience/src/index.d.ts +0 -17
  33. package/dist/umd/web-experience/src/web-experience-processor.d.ts +0 -51
  34. package/dist/umd/web-experience.umd.js +0 -428
  35. package/dist/umd/web-experience.umd.js.map +0 -1
  36. package/dist/umd/web-experience.umd.min.js +0 -19
  37. package/dist/umd/web-experience.umd.min.js.map +0 -1
@@ -1,428 +0,0 @@
1
- /* @preserve
2
- * @esri/solution-web-experience - v1.7.0 - Apache-2.0
3
- * Copyright (c) 2018-2023 Esri, Inc.
4
- * Fri Apr 28 2023 11:23:23 GMT-0700 (Pacific Daylight Time)
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
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 = 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
-
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
- }
45
-
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
- }
66
-
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
- }
102
-
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
- }
218
-
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
- }
246
-
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";
306
-
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
- }
415
-
416
- var webExperienceProcessor = /*#__PURE__*/Object.freeze({
417
- __proto__: null,
418
- convertItemToTemplate: convertItemToTemplate,
419
- createItemFromTemplate: createItemFromTemplate,
420
- postProcess: postProcess
421
- });
422
-
423
- exports.WebExperienceProcessor = webExperienceProcessor;
424
-
425
- Object.defineProperty(exports, '__esModule', { value: true });
426
-
427
- }));
428
- //# sourceMappingURL=web-experience.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"web-experience.umd.js","sources":["../../src/helpers/get-experience-subdomain.ts","../../src/helpers/get-web-experience-url-template.ts","../../src/helpers/create-web-experience-model-from-template.ts","../../src/helpers/create-web-experience.ts","../../src/helpers/get-web-experience-dependencies.ts","../../src/helpers/convert-web-experience-to-template.ts","../../src/web-experience-processor.ts"],"sourcesContent":["/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nimport { UserSession } from \"@esri/solution-common\";\r\n\r\n/**\r\n * Returns the subdomain for an experience based on the api the session is\r\n * authenticated against\r\n *\r\n * @param authentication UserSession\r\n */\r\nexport function getExperienceSubdomain(authentication: UserSession): string {\r\n const portalUrl =\r\n authentication.portal || \"https://www.arcgis.com/sharing/rest\";\r\n // TODO: Sort out how we locate experiences on portal?\r\n let result;\r\n if (portalUrl.match(/(qaext|\\.mapsqa)\\.arcgis.com/)) {\r\n result = \"experienceqa\";\r\n } else if (portalUrl.match(/(devext|\\.mapsdevext)\\.arcgis.com/)) {\r\n result = \"experiencedev\";\r\n } else if (portalUrl.match(/(www|\\.maps)\\.arcgis.com/)) {\r\n result = \"experience\";\r\n }\r\n return result;\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nimport { UserSession } from \"@esri/solution-common\";\r\nimport { getExperienceSubdomain } from \"./get-experience-subdomain\";\r\n/**\r\n * For a given environment Prod/qa/dev/portal\r\n * return the correct storymaps base url\r\n *\r\n * @param authentication\r\n */\r\nexport function getWebExperiencepUrlTemplate(\r\n authentication: UserSession\r\n): string {\r\n let baseUrl = \"\";\r\n\r\n const subdomain = getExperienceSubdomain(authentication);\r\n if (subdomain) {\r\n baseUrl = `https://${subdomain}.arcgis.com/experience/{{appid}}`;\r\n } else {\r\n // we're on portal\r\n // chop off the /sharing/rest to get the baseUrl\r\n const portalBaseUrl = authentication.portal.replace(\"/sharing/rest\", \"\");\r\n baseUrl = `${portalBaseUrl}/apps/experiencebuilder/?id={{appid}}`;\r\n }\r\n\r\n return baseUrl;\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\nimport { interpolate, IModelTemplate } from \"@esri/hub-common\";\r\nimport { UserSession } from \"@esri/solution-common\";\r\nimport { getWebExperiencepUrlTemplate } from \"./get-web-experience-url-template\";\r\n/**\r\n * Convert a Web Experience template into a Model that can be persisted to the Portal API\r\n *\r\n * @param templateModel Template\r\n * @param settings Hash of values to interpolate into the template\r\n * @param transforms Hash of transform functions to use in the interpolation\r\n * @param authentication UserSession\r\n */\r\nexport function createWebExperienceModelFromTemplate(\r\n templateModel: IModelTemplate,\r\n settings: any,\r\n transforms: any,\r\n authentication: UserSession\r\n): Promise<any> {\r\n // get the experience base url\r\n settings.experienceUrlTemplate = getWebExperiencepUrlTemplate(authentication);\r\n const model = interpolate(templateModel, settings, transforms);\r\n // ensure this is set - there may be some templates w/o `{{experienceTemplateUrl}}\r\n model.item.url = settings.experienceUrlTemplate;\r\n /* istanbul ignore else */\r\n if (templateModel.item.thumbnail) {\r\n model.item.thumbnail = templateModel.item.thumbnail; // interpolation trashes thumbnail binary\r\n }\r\n\r\n return Promise.resolve(model);\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nimport {\r\n IModel,\r\n cloneObject,\r\n failSafe,\r\n serializeModel,\r\n interpolateItemId,\r\n stringToBlob,\r\n objectToJsonBlob\r\n} from \"@esri/hub-common\";\r\n\r\nimport { UserSession } from \"@esri/solution-common\";\r\n\r\nimport {\r\n createItem,\r\n updateItem,\r\n addItemResource,\r\n ICreateItemOptions,\r\n ICreateItemResponse,\r\n IUpdateItemOptions,\r\n moveItem\r\n} from \"@esri/arcgis-rest-portal\";\r\n\r\n/**\r\n * Given a Model for a Web Experience, create the item in the Portal API\r\n *\r\n * @param model\r\n * @param options\r\n * @param authentication\r\n */\r\nexport function createWebExperience(\r\n model: IModel,\r\n folderId: string,\r\n options: any,\r\n authentication: UserSession\r\n): Promise<IModel> {\r\n const resources: any[] = [];\r\n\r\n // For unkown reasons we can not seem to spy on createItemInFolder\r\n // so we will create-then-move for now\r\n const createOptions: ICreateItemOptions = {\r\n // need to serialize\r\n item: serializeModel(model),\r\n authentication\r\n };\r\n\r\n /* istanbul ignore else */\r\n if (model.item.thumbnail) {\r\n createOptions.params = {\r\n // Pass thumbnail file in via params because item property is serialized, which discards a blob\r\n thumbnail: model.item.thumbnail\r\n };\r\n delete createOptions.item.thumbnail;\r\n }\r\n\r\n // Create the item\r\n return (\r\n createItem(createOptions)\r\n .then((createResponse: ICreateItemResponse) => {\r\n model.item.id = createResponse.id;\r\n\r\n const savedThumbnail = model.item.thumbnail;\r\n model = interpolateItemId(model);\r\n model.item.thumbnail = savedThumbnail; // interpolation trashes thumbnail binary\r\n\r\n // Experiences store draft data in a resource attached to the item\r\n // We'll just use the published data for the first \"draft\"\r\n // changed from stringToBlob to objectToJsonBlob for issue #742\r\n const draftResourceModel = cloneObject(model.data);\r\n resources.push({\r\n name: \"config.json\",\r\n prefix: \"config\",\r\n file: objectToJsonBlob(draftResourceModel)\r\n });\r\n // there may also be this image resources list\r\n const imageListModel = cloneObject(model.properties.imageResourcesList);\r\n if (imageListModel) {\r\n resources.push({\r\n name: \"image-resources-list.json\",\r\n prefix: \"images\",\r\n file: stringToBlob(JSON.stringify(imageListModel))\r\n });\r\n }\r\n\r\n delete model.properties;\r\n // update the experience with the newly interpolated model\r\n const updateOptions: IUpdateItemOptions = {\r\n item: serializeModel(model),\r\n authentication\r\n };\r\n if (model.item.thumbnail) {\r\n updateOptions.params = {\r\n // Pass thumbnail file in via params because item property is serialized, which discards a blob\r\n thumbnail: model.item.thumbnail\r\n };\r\n delete updateOptions.item.thumbnail;\r\n }\r\n\r\n return Promise.all([\r\n updateItem(updateOptions),\r\n authentication.getUsername()\r\n ]);\r\n })\r\n .then((responses: any[]) => {\r\n const username = responses[1];\r\n const failSafeAddItemResource = failSafe(addItemResource, {\r\n success: true\r\n });\r\n // upload the data and oembed resources\r\n const resourceUploadPromises = resources.map(resource =>\r\n failSafeAddItemResource({\r\n id: model.item.id,\r\n owner: username,\r\n resource: resource.file,\r\n name: resource.name,\r\n prefix: resource.prefix,\r\n authentication\r\n })\r\n );\r\n // fire and forget\r\n return Promise.all(resourceUploadPromises);\r\n })\r\n // .then(() => {\r\n // // TODO: Can we leave this to the main process?\r\n // return uploadResourcesFromUrl(model, options.assets || [], authentication);\r\n // })\r\n .then(() => {\r\n // Move it\r\n return moveItem({\r\n itemId: model.item.id,\r\n folderId,\r\n authentication\r\n });\r\n })\r\n .then(() => {\r\n return model;\r\n })\r\n );\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\nimport { IModel, getProp, maybePush } from \"@esri/hub-common\";\r\n\r\n/**\r\n * Given an Web Experience model, extract out all the\r\n * items it depends on from the `dataSources` hash\r\n *\r\n * @param model IModel\r\n */\r\nexport function getWebExperienceDependencies(model: IModel): any[] {\r\n const dataSources = getProp(model, \"data.dataSources\") || {};\r\n return Object.keys(dataSources).reduce((acc, key) => {\r\n return maybePush(getProp(dataSources, `${key}.itemId`), acc);\r\n }, []);\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\nimport {\r\n IModel,\r\n normalizeSolutionTemplateItem,\r\n cloneObject,\r\n propifyString,\r\n createId\r\n} from \"@esri/hub-common\";\r\n\r\nimport {\r\n IItemTemplate,\r\n createPlaceholderTemplate\r\n} from \"@esri/solution-common\";\r\nimport { IItem } from \"@esri/arcgis-rest-portal\";\r\nimport { getWebExperienceDependencies } from \"./get-web-experience-dependencies\";\r\n\r\n/**\r\n * Convert an Experience item into a template\r\n *\r\n * Pretty simpler conversion - remove extra item props, extract out\r\n * items from the data.dataSources hash.\r\n *\r\n * @param model\r\n * @param authentication\r\n */\r\nexport function convertWebExperienceToTemplate(\r\n model: IModel\r\n): Promise<IItemTemplate> {\r\n const tmpl = createPlaceholderTemplate(model.item.id, model.item.type);\r\n tmpl.key = `${propifyString(model.item.title)}_${createId(\"i\")}`;\r\n\r\n const clone = cloneObject(model);\r\n tmpl.data = clone.data;\r\n\r\n // We need to save these properties in order to restore them after hub.js deletes them\r\n const created = clone.item.created;\r\n const modified = clone.item.modified;\r\n tmpl.item = normalizeSolutionTemplateItem(clone.item) as IItem;\r\n tmpl.item.created = created;\r\n tmpl.item.modified = modified;\r\n\r\n // templatize the url. This is updated during the createModelFromTemplate phase\r\n // of the deployment process\r\n tmpl.item.url = \"{{experienceUrlTemplate}}\";\r\n\r\n // use typeKeyword to mark item as published (we decided to discard unpublished drafts)\r\n const typeKeywords = tmpl.item.typeKeywords;\r\n if (typeKeywords.indexOf(changedTypeKW) !== -1) {\r\n tmpl.item.typeKeywords = [publishedTypeKW].concat(\r\n tmpl.item.typeKeywords.filter(word => word !== changedTypeKW)\r\n );\r\n }\r\n\r\n tmpl.dependencies = getWebExperienceDependencies(model);\r\n\r\n return Promise.resolve(tmpl);\r\n // TODO: For now, we let the generic process handle item resources\r\n // However, many newer item types have complex type-specific resource handling\r\n // requirements so this code may be useful in the future\r\n // ------------------------------------------------------\r\n // return getItemResources(tmpl.itemId, authentication)\r\n // .then((response) => {\r\n // tmpl.resources = response.resources.map(e => e.resource)\r\n // // Discard draft version\r\n // .filter(filename => filename !== 'config.json');\r\n // return tmpl;\r\n // });\r\n}\r\n\r\nconst publishedTypeKW = \"status: Published\";\r\nconst changedTypeKW = \"status: Changed\";\r\n","/** @license\r\n * Copyright 2018 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\n/**\r\n * Manages the creation and deployment of web-experience item types.\r\n *\r\n * @module solution-web-experience\r\n */\r\n\r\nimport {\r\n UserSession,\r\n EItemProgressStatus,\r\n IItemProgressCallback,\r\n IItemTemplate,\r\n ICreateItemFromTemplateResponse,\r\n IUpdateItemResponse,\r\n generateEmptyCreationResponse,\r\n updateItemTemplateFromDictionary\r\n} from \"@esri/solution-common\";\r\nimport { IModel, failSafe } from \"@esri/hub-common\";\r\nimport { getItemData, removeItem } from \"@esri/arcgis-rest-portal\";\r\nimport { createWebExperienceModelFromTemplate } from \"./helpers/create-web-experience-model-from-template\";\r\nimport { createWebExperience } from \"./helpers/create-web-experience\";\r\nimport { convertWebExperienceToTemplate } from \"./helpers/convert-web-experience-to-template\";\r\n\r\n/**\r\n * Convert a Web Experience item into a Template\r\n *\r\n * @param solutionItemId\r\n * @param itemInfo\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @param isGroup\r\n */\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any,\r\n destAuthentication: UserSession,\r\n srcAuthentication: UserSession\r\n): Promise<IItemTemplate> {\r\n // use the itemInfo to setup a model\r\n const model = {\r\n item: itemInfo,\r\n data: {}\r\n } as IModel;\r\n // fetch the data.json\r\n return getItemData(itemInfo.id, { authentication: srcAuthentication }).then(data => {\r\n // append into the model\r\n model.data = data;\r\n // and use that to create a template\r\n return convertWebExperienceToTemplate(model);\r\n });\r\n}\r\n\r\n/**\r\n * Create a Web Experience from a Template\r\n *\r\n * @param template\r\n * @param templateDictionary\r\n * @param destinationAuthentication\r\n * @param itemProgressCallback\r\n */\r\nexport function createItemFromTemplate(\r\n template: IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: UserSession,\r\n itemProgressCallback: IItemProgressCallback\r\n): Promise<ICreateItemFromTemplateResponse> {\r\n // let the progress system know we've started...\r\n const startStatus = itemProgressCallback(\r\n template.itemId,\r\n EItemProgressStatus.Started,\r\n 0\r\n );\r\n\r\n // and if it returned false, just resolve out\r\n if (!startStatus) {\r\n return Promise.resolve(generateEmptyCreationResponse(template.type));\r\n }\r\n\r\n let exbModel: IModel;\r\n return createWebExperienceModelFromTemplate(\r\n template,\r\n templateDictionary,\r\n {},\r\n destinationAuthentication\r\n )\r\n .then(model => {\r\n exbModel = model;\r\n return createWebExperience(\r\n model,\r\n templateDictionary.folderId,\r\n {},\r\n destinationAuthentication\r\n );\r\n })\r\n .then(createdModel => {\r\n exbModel.item.id = createdModel.item.id;\r\n exbModel.item.url = createdModel.item.url;\r\n // Update the template dictionary\r\n // TODO: This should be done in whatever recieves\r\n // the outcome of this promise chain\r\n templateDictionary[template.itemId] = {\r\n itemId: createdModel.item.id\r\n };\r\n const finalStatus = itemProgressCallback(\r\n template.itemId,\r\n EItemProgressStatus.Finished,\r\n template.estimatedDeploymentCostFactor || 2,\r\n createdModel.item.id\r\n );\r\n\r\n if (!finalStatus) {\r\n // clean up the site we just created\r\n const failSafeRemove = failSafe(removeItem, { success: true });\r\n return failSafeRemove({\r\n id: exbModel.item.id,\r\n authentication: destinationAuthentication\r\n }).then(() => {\r\n return Promise.resolve(generateEmptyCreationResponse(template.type));\r\n });\r\n } else {\r\n // finally, return ICreateItemFromTemplateResponse\r\n const response: ICreateItemFromTemplateResponse = {\r\n item: {\r\n ...template,\r\n ...exbModel\r\n },\r\n id: exbModel.item.id,\r\n type: template.type,\r\n postProcess: false\r\n };\r\n response.item.itemId = exbModel.item.id;\r\n return response;\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Post-Process an Experience\r\n *\r\n * @param {string} itemId The item ID\r\n * @param {string} type The template type\r\n * @param {any[]} itemInfos Array of \\{id: 'ef3', type: 'Web Map'\\} objects\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} authentication The destination session info\r\n * @returns Promise resolving to successfulness of update\r\n */\r\nexport function postProcess(\r\n itemId: string,\r\n type: string,\r\n itemInfos: any[],\r\n template: IItemTemplate,\r\n templates: IItemTemplate[],\r\n templateDictionary: any,\r\n authentication: UserSession\r\n): Promise<IUpdateItemResponse> {\r\n return updateItemTemplateFromDictionary(\r\n itemId,\r\n templateDictionary,\r\n authentication\r\n );\r\n}\r\n"],"names":["interpolate","serializeModel","createItem","interpolateItemId","cloneObject","objectToJsonBlob","stringToBlob","updateItem","failSafe","addItemResource","moveItem","getProp","maybePush","createPlaceholderTemplate","propifyString","createId","normalizeSolutionTemplateItem","getItemData","EItemProgressStatus","generateEmptyCreationResponse","removeItem","updateItemTemplateFromDictionary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AAM,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;EACxC,YAAA,OAAO,QAAQ,CAAC;EACjB,SAAA;EACH,KAAC,CAAC,CAAC;EACP,CAAC;EAED;;;;;;;;;EASG;EACa,SAAA,WAAW,CACzB,MAAc,EACd,IAAY,EACZ,SAAgB,EAChB,QAAuB,EACvB,SAA0B,EAC1B,kBAAuB,EACvB,cAA2B,EAAA;MAE3B,OAAOE,+CAAgC,CACrC,MAAM,EACN,kBAAkB,EAClB,cAAc,CACf,CAAC;EACJ;;;;;;;;;;;;;;;;;"}
@@ -1,19 +0,0 @@
1
- /* @preserve
2
- * @esri/solution-web-experience - v1.7.0 - Apache-2.0
3
- * Copyright (c) 2018-2023 Esri, Inc.
4
- * Fri Apr 28 2023 11:23:28 GMT-0700 (Pacific Daylight Time)
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@esri/solution-common"),require("@esri/hub-common"),require("@esri/arcgis-rest-portal")):"function"==typeof define&&define.amd?define(["exports","@esri/solution-common","@esri/hub-common","@esri/arcgis-rest-portal"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).arcgisSolution=e.arcgisSolution||{},e.arcgisSolution,e.arcgisHub,e.arcgisRest)}(this,(function(e,t,i,r){"use strict";function n(e){const r=t.createPlaceholderTemplate(e.item.id,e.item.type);r.key=`${i.propifyString(e.item.title)}_${i.createId("i")}`;const n=i.cloneObject(e);r.data=n.data;const m=n.item.created,s=n.item.modified;r.item=i.normalizeSolutionTemplateItem(n.item),r.item.created=m,r.item.modified=s,r.item.url="{{experienceUrlTemplate}}";return-1!==r.item.typeKeywords.indexOf(a)&&(r.item.typeKeywords=[o].concat(r.item.typeKeywords.filter((e=>e!==a)))),r.dependencies=function(e){const t=i.getProp(e,"data.dataSources")||{};return Object.keys(t).reduce(((e,r)=>i.maybePush(i.getProp(t,`${r}.itemId`),e)),[])}(e),Promise.resolve(r)}const o="status: Published",a="status: Changed";var m=Object.freeze({__proto__:null,convertItemToTemplate:function(e,t,i,o){const a={item:t,data:{}};return r.getItemData(t.id,{authentication:o}).then((e=>(a.data=e,n(a))))},createItemFromTemplate:function(e,n,o,a){if(!a(e.itemId,t.EItemProgressStatus.Started,0))return Promise.resolve(t.generateEmptyCreationResponse(e.type));let m;return function(e,t,r,n){t.experienceUrlTemplate=function(e){let t="";const i=function(e){const t=e.portal||"https://www.arcgis.com/sharing/rest";let i;return t.match(/(qaext|\.mapsqa)\.arcgis.com/)?i="experienceqa":t.match(/(devext|\.mapsdevext)\.arcgis.com/)?i="experiencedev":t.match(/(www|\.maps)\.arcgis.com/)&&(i="experience"),i}(e);return t=i?`https://${i}.arcgis.com/experience/{{appid}}`:`${e.portal.replace("/sharing/rest","")}/apps/experiencebuilder/?id={{appid}}`,t}(n);const o=i.interpolate(e,t,r);return o.item.url=t.experienceUrlTemplate,e.item.thumbnail&&(o.item.thumbnail=e.item.thumbnail),Promise.resolve(o)}(e,n,{},o).then((e=>(m=e,function(e,t,n,o){const a=[],m={item:i.serializeModel(e),authentication:o};return e.item.thumbnail&&(m.params={thumbnail:e.item.thumbnail},delete m.item.thumbnail),r.createItem(m).then((t=>{e.item.id=t.id;const n=e.item.thumbnail;(e=i.interpolateItemId(e)).item.thumbnail=n;const m=i.cloneObject(e.data);a.push({name:"config.json",prefix:"config",file:i.objectToJsonBlob(m)});const s=i.cloneObject(e.properties.imageResourcesList);s&&a.push({name:"image-resources-list.json",prefix:"images",file:i.stringToBlob(JSON.stringify(s))}),delete e.properties;const c={item:i.serializeModel(e),authentication:o};return e.item.thumbnail&&(c.params={thumbnail:e.item.thumbnail},delete c.item.thumbnail),Promise.all([r.updateItem(c),o.getUsername()])})).then((t=>{const n=t[1],m=i.failSafe(r.addItemResource,{success:!0}),s=a.map((t=>m({id:e.item.id,owner:n,resource:t.file,name:t.name,prefix:t.prefix,authentication:o})));return Promise.all(s)})).then((()=>r.moveItem({itemId:e.item.id,folderId:t,authentication:o}))).then((()=>e))}(e,n.folderId,0,o)))).then((s=>{m.item.id=s.item.id,m.item.url=s.item.url,n[e.itemId]={itemId:s.item.id};if(a(e.itemId,t.EItemProgressStatus.Finished,e.estimatedDeploymentCostFactor||2,s.item.id)){const t={item:{...e,...m},id:m.item.id,type:e.type,postProcess:!1};return t.item.itemId=m.item.id,t}return i.failSafe(r.removeItem,{success:!0})({id:m.item.id,authentication:o}).then((()=>Promise.resolve(t.generateEmptyCreationResponse(e.type))))}))},postProcess:function(e,i,r,n,o,a,m){return t.updateItemTemplateFromDictionary(e,a,m)}});e.WebExperienceProcessor=m,Object.defineProperty(e,"__esModule",{value:!0})}));
19
- //# sourceMappingURL=web-experience.umd.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"web-experience.umd.min.js","sources":["../../src/helpers/convert-web-experience-to-template.ts","../../src/helpers/get-web-experience-dependencies.ts","../../src/web-experience-processor.ts","../../src/helpers/create-web-experience-model-from-template.ts","../../src/helpers/get-web-experience-url-template.ts","../../src/helpers/get-experience-subdomain.ts","../../src/helpers/create-web-experience.ts"],"sourcesContent":["/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\nimport {\r\n IModel,\r\n normalizeSolutionTemplateItem,\r\n cloneObject,\r\n propifyString,\r\n createId\r\n} from \"@esri/hub-common\";\r\n\r\nimport {\r\n IItemTemplate,\r\n createPlaceholderTemplate\r\n} from \"@esri/solution-common\";\r\nimport { IItem } from \"@esri/arcgis-rest-portal\";\r\nimport { getWebExperienceDependencies } from \"./get-web-experience-dependencies\";\r\n\r\n/**\r\n * Convert an Experience item into a template\r\n *\r\n * Pretty simpler conversion - remove extra item props, extract out\r\n * items from the data.dataSources hash.\r\n *\r\n * @param model\r\n * @param authentication\r\n */\r\nexport function convertWebExperienceToTemplate(\r\n model: IModel\r\n): Promise<IItemTemplate> {\r\n const tmpl = createPlaceholderTemplate(model.item.id, model.item.type);\r\n tmpl.key = `${propifyString(model.item.title)}_${createId(\"i\")}`;\r\n\r\n const clone = cloneObject(model);\r\n tmpl.data = clone.data;\r\n\r\n // We need to save these properties in order to restore them after hub.js deletes them\r\n const created = clone.item.created;\r\n const modified = clone.item.modified;\r\n tmpl.item = normalizeSolutionTemplateItem(clone.item) as IItem;\r\n tmpl.item.created = created;\r\n tmpl.item.modified = modified;\r\n\r\n // templatize the url. This is updated during the createModelFromTemplate phase\r\n // of the deployment process\r\n tmpl.item.url = \"{{experienceUrlTemplate}}\";\r\n\r\n // use typeKeyword to mark item as published (we decided to discard unpublished drafts)\r\n const typeKeywords = tmpl.item.typeKeywords;\r\n if (typeKeywords.indexOf(changedTypeKW) !== -1) {\r\n tmpl.item.typeKeywords = [publishedTypeKW].concat(\r\n tmpl.item.typeKeywords.filter(word => word !== changedTypeKW)\r\n );\r\n }\r\n\r\n tmpl.dependencies = getWebExperienceDependencies(model);\r\n\r\n return Promise.resolve(tmpl);\r\n // TODO: For now, we let the generic process handle item resources\r\n // However, many newer item types have complex type-specific resource handling\r\n // requirements so this code may be useful in the future\r\n // ------------------------------------------------------\r\n // return getItemResources(tmpl.itemId, authentication)\r\n // .then((response) => {\r\n // tmpl.resources = response.resources.map(e => e.resource)\r\n // // Discard draft version\r\n // .filter(filename => filename !== 'config.json');\r\n // return tmpl;\r\n // });\r\n}\r\n\r\nconst publishedTypeKW = \"status: Published\";\r\nconst changedTypeKW = \"status: Changed\";\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\nimport { IModel, getProp, maybePush } from \"@esri/hub-common\";\r\n\r\n/**\r\n * Given an Web Experience model, extract out all the\r\n * items it depends on from the `dataSources` hash\r\n *\r\n * @param model IModel\r\n */\r\nexport function getWebExperienceDependencies(model: IModel): any[] {\r\n const dataSources = getProp(model, \"data.dataSources\") || {};\r\n return Object.keys(dataSources).reduce((acc, key) => {\r\n return maybePush(getProp(dataSources, `${key}.itemId`), acc);\r\n }, []);\r\n}\r\n","/** @license\r\n * Copyright 2018 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\n/**\r\n * Manages the creation and deployment of web-experience item types.\r\n *\r\n * @module solution-web-experience\r\n */\r\n\r\nimport {\r\n UserSession,\r\n EItemProgressStatus,\r\n IItemProgressCallback,\r\n IItemTemplate,\r\n ICreateItemFromTemplateResponse,\r\n IUpdateItemResponse,\r\n generateEmptyCreationResponse,\r\n updateItemTemplateFromDictionary\r\n} from \"@esri/solution-common\";\r\nimport { IModel, failSafe } from \"@esri/hub-common\";\r\nimport { getItemData, removeItem } from \"@esri/arcgis-rest-portal\";\r\nimport { createWebExperienceModelFromTemplate } from \"./helpers/create-web-experience-model-from-template\";\r\nimport { createWebExperience } from \"./helpers/create-web-experience\";\r\nimport { convertWebExperienceToTemplate } from \"./helpers/convert-web-experience-to-template\";\r\n\r\n/**\r\n * Convert a Web Experience item into a Template\r\n *\r\n * @param solutionItemId\r\n * @param itemInfo\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @param isGroup\r\n */\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any,\r\n destAuthentication: UserSession,\r\n srcAuthentication: UserSession\r\n): Promise<IItemTemplate> {\r\n // use the itemInfo to setup a model\r\n const model = {\r\n item: itemInfo,\r\n data: {}\r\n } as IModel;\r\n // fetch the data.json\r\n return getItemData(itemInfo.id, { authentication: srcAuthentication }).then(data => {\r\n // append into the model\r\n model.data = data;\r\n // and use that to create a template\r\n return convertWebExperienceToTemplate(model);\r\n });\r\n}\r\n\r\n/**\r\n * Create a Web Experience from a Template\r\n *\r\n * @param template\r\n * @param templateDictionary\r\n * @param destinationAuthentication\r\n * @param itemProgressCallback\r\n */\r\nexport function createItemFromTemplate(\r\n template: IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: UserSession,\r\n itemProgressCallback: IItemProgressCallback\r\n): Promise<ICreateItemFromTemplateResponse> {\r\n // let the progress system know we've started...\r\n const startStatus = itemProgressCallback(\r\n template.itemId,\r\n EItemProgressStatus.Started,\r\n 0\r\n );\r\n\r\n // and if it returned false, just resolve out\r\n if (!startStatus) {\r\n return Promise.resolve(generateEmptyCreationResponse(template.type));\r\n }\r\n\r\n let exbModel: IModel;\r\n return createWebExperienceModelFromTemplate(\r\n template,\r\n templateDictionary,\r\n {},\r\n destinationAuthentication\r\n )\r\n .then(model => {\r\n exbModel = model;\r\n return createWebExperience(\r\n model,\r\n templateDictionary.folderId,\r\n {},\r\n destinationAuthentication\r\n );\r\n })\r\n .then(createdModel => {\r\n exbModel.item.id = createdModel.item.id;\r\n exbModel.item.url = createdModel.item.url;\r\n // Update the template dictionary\r\n // TODO: This should be done in whatever recieves\r\n // the outcome of this promise chain\r\n templateDictionary[template.itemId] = {\r\n itemId: createdModel.item.id\r\n };\r\n const finalStatus = itemProgressCallback(\r\n template.itemId,\r\n EItemProgressStatus.Finished,\r\n template.estimatedDeploymentCostFactor || 2,\r\n createdModel.item.id\r\n );\r\n\r\n if (!finalStatus) {\r\n // clean up the site we just created\r\n const failSafeRemove = failSafe(removeItem, { success: true });\r\n return failSafeRemove({\r\n id: exbModel.item.id,\r\n authentication: destinationAuthentication\r\n }).then(() => {\r\n return Promise.resolve(generateEmptyCreationResponse(template.type));\r\n });\r\n } else {\r\n // finally, return ICreateItemFromTemplateResponse\r\n const response: ICreateItemFromTemplateResponse = {\r\n item: {\r\n ...template,\r\n ...exbModel\r\n },\r\n id: exbModel.item.id,\r\n type: template.type,\r\n postProcess: false\r\n };\r\n response.item.itemId = exbModel.item.id;\r\n return response;\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Post-Process an Experience\r\n *\r\n * @param {string} itemId The item ID\r\n * @param {string} type The template type\r\n * @param {any[]} itemInfos Array of \\{id: 'ef3', type: 'Web Map'\\} objects\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} authentication The destination session info\r\n * @returns Promise resolving to successfulness of update\r\n */\r\nexport function postProcess(\r\n itemId: string,\r\n type: string,\r\n itemInfos: any[],\r\n template: IItemTemplate,\r\n templates: IItemTemplate[],\r\n templateDictionary: any,\r\n authentication: UserSession\r\n): Promise<IUpdateItemResponse> {\r\n return updateItemTemplateFromDictionary(\r\n itemId,\r\n templateDictionary,\r\n authentication\r\n );\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\nimport { interpolate, IModelTemplate } from \"@esri/hub-common\";\r\nimport { UserSession } from \"@esri/solution-common\";\r\nimport { getWebExperiencepUrlTemplate } from \"./get-web-experience-url-template\";\r\n/**\r\n * Convert a Web Experience template into a Model that can be persisted to the Portal API\r\n *\r\n * @param templateModel Template\r\n * @param settings Hash of values to interpolate into the template\r\n * @param transforms Hash of transform functions to use in the interpolation\r\n * @param authentication UserSession\r\n */\r\nexport function createWebExperienceModelFromTemplate(\r\n templateModel: IModelTemplate,\r\n settings: any,\r\n transforms: any,\r\n authentication: UserSession\r\n): Promise<any> {\r\n // get the experience base url\r\n settings.experienceUrlTemplate = getWebExperiencepUrlTemplate(authentication);\r\n const model = interpolate(templateModel, settings, transforms);\r\n // ensure this is set - there may be some templates w/o `{{experienceTemplateUrl}}\r\n model.item.url = settings.experienceUrlTemplate;\r\n /* istanbul ignore else */\r\n if (templateModel.item.thumbnail) {\r\n model.item.thumbnail = templateModel.item.thumbnail; // interpolation trashes thumbnail binary\r\n }\r\n\r\n return Promise.resolve(model);\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nimport { UserSession } from \"@esri/solution-common\";\r\nimport { getExperienceSubdomain } from \"./get-experience-subdomain\";\r\n/**\r\n * For a given environment Prod/qa/dev/portal\r\n * return the correct storymaps base url\r\n *\r\n * @param authentication\r\n */\r\nexport function getWebExperiencepUrlTemplate(\r\n authentication: UserSession\r\n): string {\r\n let baseUrl = \"\";\r\n\r\n const subdomain = getExperienceSubdomain(authentication);\r\n if (subdomain) {\r\n baseUrl = `https://${subdomain}.arcgis.com/experience/{{appid}}`;\r\n } else {\r\n // we're on portal\r\n // chop off the /sharing/rest to get the baseUrl\r\n const portalBaseUrl = authentication.portal.replace(\"/sharing/rest\", \"\");\r\n baseUrl = `${portalBaseUrl}/apps/experiencebuilder/?id={{appid}}`;\r\n }\r\n\r\n return baseUrl;\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nimport { UserSession } from \"@esri/solution-common\";\r\n\r\n/**\r\n * Returns the subdomain for an experience based on the api the session is\r\n * authenticated against\r\n *\r\n * @param authentication UserSession\r\n */\r\nexport function getExperienceSubdomain(authentication: UserSession): string {\r\n const portalUrl =\r\n authentication.portal || \"https://www.arcgis.com/sharing/rest\";\r\n // TODO: Sort out how we locate experiences on portal?\r\n let result;\r\n if (portalUrl.match(/(qaext|\\.mapsqa)\\.arcgis.com/)) {\r\n result = \"experienceqa\";\r\n } else if (portalUrl.match(/(devext|\\.mapsdevext)\\.arcgis.com/)) {\r\n result = \"experiencedev\";\r\n } else if (portalUrl.match(/(www|\\.maps)\\.arcgis.com/)) {\r\n result = \"experience\";\r\n }\r\n return result;\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nimport {\r\n IModel,\r\n cloneObject,\r\n failSafe,\r\n serializeModel,\r\n interpolateItemId,\r\n stringToBlob,\r\n objectToJsonBlob\r\n} from \"@esri/hub-common\";\r\n\r\nimport { UserSession } from \"@esri/solution-common\";\r\n\r\nimport {\r\n createItem,\r\n updateItem,\r\n addItemResource,\r\n ICreateItemOptions,\r\n ICreateItemResponse,\r\n IUpdateItemOptions,\r\n moveItem\r\n} from \"@esri/arcgis-rest-portal\";\r\n\r\n/**\r\n * Given a Model for a Web Experience, create the item in the Portal API\r\n *\r\n * @param model\r\n * @param options\r\n * @param authentication\r\n */\r\nexport function createWebExperience(\r\n model: IModel,\r\n folderId: string,\r\n options: any,\r\n authentication: UserSession\r\n): Promise<IModel> {\r\n const resources: any[] = [];\r\n\r\n // For unkown reasons we can not seem to spy on createItemInFolder\r\n // so we will create-then-move for now\r\n const createOptions: ICreateItemOptions = {\r\n // need to serialize\r\n item: serializeModel(model),\r\n authentication\r\n };\r\n\r\n /* istanbul ignore else */\r\n if (model.item.thumbnail) {\r\n createOptions.params = {\r\n // Pass thumbnail file in via params because item property is serialized, which discards a blob\r\n thumbnail: model.item.thumbnail\r\n };\r\n delete createOptions.item.thumbnail;\r\n }\r\n\r\n // Create the item\r\n return (\r\n createItem(createOptions)\r\n .then((createResponse: ICreateItemResponse) => {\r\n model.item.id = createResponse.id;\r\n\r\n const savedThumbnail = model.item.thumbnail;\r\n model = interpolateItemId(model);\r\n model.item.thumbnail = savedThumbnail; // interpolation trashes thumbnail binary\r\n\r\n // Experiences store draft data in a resource attached to the item\r\n // We'll just use the published data for the first \"draft\"\r\n // changed from stringToBlob to objectToJsonBlob for issue #742\r\n const draftResourceModel = cloneObject(model.data);\r\n resources.push({\r\n name: \"config.json\",\r\n prefix: \"config\",\r\n file: objectToJsonBlob(draftResourceModel)\r\n });\r\n // there may also be this image resources list\r\n const imageListModel = cloneObject(model.properties.imageResourcesList);\r\n if (imageListModel) {\r\n resources.push({\r\n name: \"image-resources-list.json\",\r\n prefix: \"images\",\r\n file: stringToBlob(JSON.stringify(imageListModel))\r\n });\r\n }\r\n\r\n delete model.properties;\r\n // update the experience with the newly interpolated model\r\n const updateOptions: IUpdateItemOptions = {\r\n item: serializeModel(model),\r\n authentication\r\n };\r\n if (model.item.thumbnail) {\r\n updateOptions.params = {\r\n // Pass thumbnail file in via params because item property is serialized, which discards a blob\r\n thumbnail: model.item.thumbnail\r\n };\r\n delete updateOptions.item.thumbnail;\r\n }\r\n\r\n return Promise.all([\r\n updateItem(updateOptions),\r\n authentication.getUsername()\r\n ]);\r\n })\r\n .then((responses: any[]) => {\r\n const username = responses[1];\r\n const failSafeAddItemResource = failSafe(addItemResource, {\r\n success: true\r\n });\r\n // upload the data and oembed resources\r\n const resourceUploadPromises = resources.map(resource =>\r\n failSafeAddItemResource({\r\n id: model.item.id,\r\n owner: username,\r\n resource: resource.file,\r\n name: resource.name,\r\n prefix: resource.prefix,\r\n authentication\r\n })\r\n );\r\n // fire and forget\r\n return Promise.all(resourceUploadPromises);\r\n })\r\n // .then(() => {\r\n // // TODO: Can we leave this to the main process?\r\n // return uploadResourcesFromUrl(model, options.assets || [], authentication);\r\n // })\r\n .then(() => {\r\n // Move it\r\n return moveItem({\r\n itemId: model.item.id,\r\n folderId,\r\n authentication\r\n });\r\n })\r\n .then(() => {\r\n return model;\r\n })\r\n );\r\n}\r\n"],"names":["convertWebExperienceToTemplate","model","tmpl","createPlaceholderTemplate","item","id","type","key","propifyString","title","createId","clone","cloneObject","data","created","modified","normalizeSolutionTemplateItem","url","typeKeywords","indexOf","changedTypeKW","publishedTypeKW","concat","filter","word","dependencies","dataSources","getProp","Object","keys","reduce","acc","maybePush","getWebExperienceDependencies","Promise","resolve","solutionItemId","itemInfo","destAuthentication","srcAuthentication","getItemData","authentication","then","template","templateDictionary","destinationAuthentication","itemProgressCallback","itemId","EItemProgressStatus","Started","generateEmptyCreationResponse","exbModel","templateModel","settings","transforms","experienceUrlTemplate","baseUrl","subdomain","portalUrl","portal","result","match","getExperienceSubdomain","replace","getWebExperiencepUrlTemplate","interpolate","thumbnail","createWebExperienceModelFromTemplate","folderId","options","resources","createOptions","serializeModel","params","createItem","createResponse","savedThumbnail","interpolateItemId","draftResourceModel","push","name","prefix","file","objectToJsonBlob","imageListModel","properties","imageResourcesList","stringToBlob","JSON","stringify","updateOptions","all","updateItem","getUsername","responses","username","failSafeAddItemResource","failSafe","addItemResource","success","resourceUploadPromises","map","resource","owner","moveItem","createWebExperience","createdModel","Finished","estimatedDeploymentCostFactor","response","postProcess","removeItem","failSafeRemove","itemInfos","templates","updateItemTemplateFromDictionary"],"mappings":";;;;;;;;;;;;;;;;;+dAwCM,SAAUA,EACdC,GAEA,MAAMC,EAAOC,EAAyBA,0BAACF,EAAMG,KAAKC,GAAIJ,EAAMG,KAAKE,MACjEJ,EAAKK,IAAM,GAAGC,EAAAA,cAAcP,EAAMG,KAAKK,UAAUC,EAAAA,SAAS,OAE1D,MAAMC,EAAQC,cAAYX,GAC1BC,EAAKW,KAAOF,EAAME,KAGlB,MAAMC,EAAUH,EAAMP,KAAKU,QACrBC,EAAWJ,EAAMP,KAAKW,SAC5Bb,EAAKE,KAAOY,EAAAA,8BAA8BL,EAAMP,MAChDF,EAAKE,KAAKU,QAAUA,EACpBZ,EAAKE,KAAKW,SAAWA,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