@esri/solution-storymap 1.3.13 → 1.3.16

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.
@@ -1,7 +1,7 @@
1
1
  /* @preserve
2
- * @esri/solution-storymap - v1.3.13 - Apache-2.0
2
+ * @esri/solution-storymap - v1.3.16 - Apache-2.0
3
3
  * Copyright (c) 2018-2022 Esri, Inc.
4
- * Tue Apr 26 2022 15:03:57 GMT-0700 (Pacific Daylight Time)
4
+ * Wed Jun 08 2022 10:59:17 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.
@@ -1 +1 @@
1
- {"version":3,"file":"storymap.umd.js","sources":["../../src/helpers/remap-webmap-keys.ts","../../src/helpers/get-storymap-dependencies.ts","../../src/helpers/convert-storymap-to-template.ts","../../src/helpers/get-portal-env.ts","../../src/helpers/get-storymap-subdomain.ts","../../src/helpers/get-storymap-base-url.ts","../../src/helpers/create-storymap-model-from-template.ts","../../src/helpers/create-storymap.ts","../../src/storymap-processor.ts","../../src/classic-storymap-processor.ts"],"sourcesContent":["/** @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\nimport { getProp } from \"@esri/hub-common\";\r\n\r\n/**\r\n * For some reason, the webmap resource key names are fancier than other resource keys\r\n * They look like this: r-<webmap-item-id>-<timestamp>\r\n * This interpolation is hard to accomplish given our current setup, so we're just overwriting\r\n * them with \"webmap0\", \"webmap1\" and so forth. This _seems_ to make no difference.\r\n *\r\n * @param model\r\n */\r\nexport function remapWebmapKeys(resources: any = {}): any[] {\r\n let webmapCounter = 0;\r\n return Object.keys(resources).reduce((acc, key) => {\r\n if (getProp(resources, `${key}.type`) === \"webmap\") {\r\n if (key !== `webmap${webmapCounter}`) {\r\n acc.push({\r\n original: key,\r\n updated: `webmap${webmapCounter}`\r\n });\r\n webmapCounter++;\r\n }\r\n }\r\n return 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\nimport { IModel, getProp } from \"@esri/hub-common\";\r\n\r\n/**\r\n * Extract a list of Items this storymap depends on\r\n * At this point we are just extracting webmaps\r\n *\r\n * @param model IModel\r\n */\r\nexport function getStoryMapDependencies(model: IModel): any[] {\r\n const resources = getProp(model, \"data.resources\") || {};\r\n return Object.keys(resources).reduce((acc, key) => {\r\n if (getProp(resources, `${key}.type`) === \"webmap\") {\r\n acc.push(getProp(resources, `${key}.data.itemId`));\r\n }\r\n return 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\nimport {\r\n IModel,\r\n cloneObject,\r\n propifyString,\r\n createId,\r\n normalizeSolutionTemplateItem,\r\n deepStringReplace\r\n} from \"@esri/hub-common\";\r\nimport { IItem } from \"@esri/arcgis-rest-portal\";\r\nimport {\r\n IItemTemplate,\r\n createPlaceholderTemplate\r\n} from \"@esri/solution-common\";\r\nimport { remapWebmapKeys } from \"./remap-webmap-keys\";\r\nimport { getStoryMapDependencies } from \"./get-storymap-dependencies\";\r\n\r\n/**\r\n * Convert a StoryMap IModel to an IItemTemplate\r\n *\r\n * @param model\r\n * @param authentication\r\n */\r\nexport function convertStoryMapToTemplate(\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\r\n tmpl.item.url = \"{{storyMapTemplateUrl}}\";\r\n\r\n // Storymap Webmap Resources have complex keys that we need to remap\r\n const webmapRemaps = remapWebmapKeys(tmpl.data.resources);\r\n // and then replace in the rest of the structure\r\n webmapRemaps.forEach(remap => {\r\n tmpl.data.resources[remap.updated] = cloneObject(\r\n tmpl.data.resources[remap.original]\r\n );\r\n delete tmpl.data.resources[remap.original];\r\n tmpl.data.nodes = deepStringReplace(\r\n tmpl.data.nodes,\r\n remap.original,\r\n remap.updated\r\n );\r\n });\r\n\r\n // use typeKeyword to mark item as published\r\n // Note: Hub team decided to discard unpublished drafts when creating a template\r\n const typeKeywords = tmpl.item.typeKeywords;\r\n if (typeKeywords.indexOf(unPublishedChangesKW) !== -1) {\r\n tmpl.item.typeKeywords = [publishedChangesKW].concat(\r\n tmpl.item.typeKeywords.filter(\r\n (word: string) => word !== unPublishedChangesKW\r\n )\r\n );\r\n }\r\n\r\n tmpl.properties = {};\r\n tmpl.properties.draftFileName = \"draft_{{timestamp}}.json\";\r\n Object.assign(tmpl.properties, oEmbedTemplates);\r\n\r\n tmpl.dependencies = getStoryMapDependencies(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, hubRequestOptions)\r\n // .then((response) => {\r\n // tmpl.resources = response.resources.map(e => e.resource)\r\n // // Don't directly copy oembed resources because we need to template these\r\n // // Also, discard draft version of the storymap itself\r\n // .filter(filename => !filename.includes('oembed') && filename.search(/draft_[0-9]+.json/) === -1);\r\n // return tmpl;\r\n // });\r\n}\r\n\r\n// Internal constants\r\nconst unPublishedChangesKW = \"smstatusunpublishedchanges\";\r\nconst publishedChangesKW = \"smstatuspublished\";\r\n\r\n/**\r\n * Template for oEmbed\r\n */\r\nconst oEmbedTemplates = {\r\n oembed: {\r\n version: \"1.0\",\r\n type: \"rich\",\r\n title: \"Example StoryMap\",\r\n url: \"{{storyMapTemplateUrl}}\",\r\n provider_name: \"ArcGIS StoryMaps\",\r\n provider_url: \"{{storyMapBaseUrl}}\",\r\n width: 800,\r\n height: 600,\r\n thumbnail_url: \"{{storyMapThumbnailUrl}}\",\r\n thumbnail_height: \"100.5\",\r\n thumbnail_width: \"400\",\r\n html:\r\n '<iframe src=\"{{storyMapTemplateUrl}}\" width=\"800\" height=\"600\" scrolling=\"yes\" frameborder=\"0\" allowfullscreen></iframe>',\r\n cache_age: 86400\r\n },\r\n oembedXML:\r\n '<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\\n <oembed>\\n <version>1.0</version>\\n <type>rich</type>\\n <title>Example StoryMap</title>\\n <url>{{storyMapTemplateUrl}}</url>\\n <author_name>undefined</author_name>\\n <provider_name>ArcGIS StoryMaps</provider_name>\\n <provider_url>{{storyMapBaseUrl}}</provider_url>\\n <width>800</width>\\n <height>600</height>\\n <thumbnail_url>{{storyMapThumbnailUrl}}</thumbnail_url>\\n <thumbnail_height>100.5</thumbnail_height>\\n <thumbnail_width>400</thumbnail_width>\\n <html><iframe src=\"{{storyMapTemplateUrl}}\" width=\"800\" height=\"600\" scrolling=\"yes\" frameborder=\"0\" allowfullscreen=\"true\"></iframe></html>\\n <cache_age>86400</cache_age>\\n </oembed>'\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\nexport function getPortalEnv(authentication: UserSession): string {\r\n const portalUrl =\r\n authentication.portal || \"https://www.arcgis.com/sharing/rest\";\r\n let result = \"portal\";\r\n if (portalUrl.match(/(qaext|\\.mapsqa)\\.arcgis.com/)) {\r\n result = \"qaext\";\r\n } else if (portalUrl.match(/(devext|\\.mapsdevext)\\.arcgis.com/)) {\r\n result = \"devext\";\r\n } else if (portalUrl.match(/(www|\\.maps)\\.arcgis.com/)) {\r\n result = \"www\";\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\n\r\nexport function getStoryMapSubdomain(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 storymaps on portal?\r\n let result;\r\n if (portalUrl.match(/(qaext|\\.mapsqa)\\.arcgis.com/)) {\r\n result = \"storymapsqa\";\r\n } else if (portalUrl.match(/(devext|\\.mapsdevext)\\.arcgis.com/)) {\r\n result = \"storymapsdev\";\r\n } else if (portalUrl.match(/(www|\\.maps)\\.arcgis.com/)) {\r\n result = \"storymaps\";\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 { getStoryMapSubdomain } from \"./get-storymap-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 getStoryMapBaseUrl(authentication: UserSession): string {\r\n let baseUrl = \"\";\r\n\r\n const subdomain = getStoryMapSubdomain(authentication);\r\n if (subdomain) {\r\n baseUrl = `https://${subdomain}.arcgis.com`;\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/storymaps`;\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\n * Given a template, process it and interpolate it such that\r\n * we have a model that is ready to be sent to the Portal API\r\n */\r\n\r\nimport { interpolate, IModelTemplate } from \"@esri/hub-common\";\r\nimport { UserSession } from \"@esri/solution-common\";\r\nimport { getPortalEnv } from \"./get-portal-env\";\r\nimport { getStoryMapBaseUrl } from \"./get-storymap-base-url\";\r\nimport { getStoryMapSubdomain } from \"./get-storymap-subdomain\";\r\n\r\nexport function createStoryMapModelFromTemplate(\r\n templateModel: IModelTemplate,\r\n settings: any,\r\n transforms: any,\r\n authentication: UserSession\r\n): Promise<any> {\r\n const timestamp = new Date().getTime();\r\n // Keep these around in case we encounter some old templates\r\n settings.agoenv = getPortalEnv(authentication);\r\n settings.smBase = getStoryMapSubdomain(authentication);\r\n settings.timestamp = new Date().getTime();\r\n // These are used in the oembed resource, as well as the item url\r\n // they have `{{appid}}` in them so that the id of the created item\r\n // will be interpolated into it after the item is created\r\n settings.storyMapBaseUrl = getStoryMapBaseUrl(authentication);\r\n settings.storyMapTemplateUrl = `${settings.storyMapBaseUrl}/stories/{{appid}}`;\r\n settings.storyMapThumnailUrl = `${authentication.portal}/content/items/{{appid}}/info/thumbnail/thumbnail.jpg/?w=400&d=${timestamp}`;\r\n\r\n const model = interpolate(templateModel, settings, transforms);\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\n\r\n// TODO ENSURE THIS CREATES IN THE TARGET FOLDER\r\nimport {\r\n IModel,\r\n failSafe,\r\n serializeModel,\r\n interpolateItemId,\r\n stringToBlob\r\n} from \"@esri/hub-common\";\r\n\r\nimport { UserSession } from \"@esri/solution-common\";\r\n\r\nimport {\r\n createItem,\r\n moveItem,\r\n addItemResource,\r\n updateItem,\r\n ICreateItemOptions,\r\n ICreateItemResponse\r\n} from \"@esri/arcgis-rest-portal\";\r\n\r\n/**\r\n * Create a StoryMap from an interpolated template\r\n *\r\n * @param model\r\n * @param options\r\n * @param authentication\r\n */\r\nexport function createStoryMap(\r\n model: IModel,\r\n folderId: string,\r\n options: any,\r\n authentication: UserSession\r\n): Promise<IModel> {\r\n // create an array to hold well-known resources\r\n // that we have to generate from the passed in model\r\n const resources: any[] = [];\r\n\r\n // For unknown 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 createItem(createOptions)\r\n .then((createResponse: ICreateItemResponse) => {\r\n // hold the id in the model\r\n model.item.id = createResponse.id;\r\n // and re-interpolate the item id\r\n model = interpolateItemId(model);\r\n // Compute the item url based on current environment\r\n\r\n // Storymaps store draft data in a timestamped resource attached to the item\r\n // We'll just use the published data for the first \"draft\"\r\n resources.push({\r\n name: model.properties.draftFileName,\r\n file: stringToBlob(JSON.stringify(model.data))\r\n });\r\n resources.push({\r\n name: \"oembed.json\",\r\n file: stringToBlob(JSON.stringify(model.properties.oembed))\r\n });\r\n resources.push({\r\n name: \"oembed.xml\",\r\n file: stringToBlob(model.properties.oembedXML)\r\n });\r\n // remove the properties hash now that we've gotten what we need\r\n delete model.properties;\r\n // update the item with the newly re-interpolated model\r\n return Promise.all([\r\n updateItem({\r\n item: serializeModel(model),\r\n authentication\r\n }),\r\n authentication.getUsername()\r\n ]);\r\n })\r\n .then((responses: any[]) => {\r\n const username = responses[1];\r\n // add the resources\r\n const failSafeAddItemResource = failSafe(addItemResource, {\r\n success: true\r\n });\r\n const resourcePromises = resources.map(resource => {\r\n return failSafeAddItemResource({\r\n id: model.item.id,\r\n owner: username,\r\n resource: resource.file,\r\n name: resource.name,\r\n authentication\r\n });\r\n });\r\n // Fire and forget as these are not critical-path\r\n return Promise.all(resourcePromises);\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","/** @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 Story Map item types.\r\n *\r\n * @module storymap\r\n */\r\n\r\nimport {\r\n IItemTemplate,\r\n IItemProgressCallback,\r\n ICreateItemFromTemplateResponse,\r\n EItemProgressStatus,\r\n UserSession,\r\n generateEmptyCreationResponse\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 { convertStoryMapToTemplate } from \"./helpers/convert-storymap-to-template\";\r\nimport { createStoryMapModelFromTemplate } from \"./helpers/create-storymap-model-from-template\";\r\nimport { createStoryMap } from \"./helpers/create-storymap\";\r\n\r\n/**\r\n * Convert a StoryMap to 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 */\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 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 })\r\n .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 convertStoryMapToTemplate(model);\r\n })\r\n .then(tmpl => {\r\n return tmpl;\r\n });\r\n}\r\n\r\n/**\r\n * Create a StoryMap from the passed in 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 // ensure we have a solution object in the templateDictionary hash\r\n if (!templateDictionary.solution) {\r\n templateDictionary.solution = {};\r\n }\r\n // .title should always be set on the templateDictionary\r\n templateDictionary.solution.title = templateDictionary.title;\r\n\r\n // TODO: Determine if we need any transforms in this new env\r\n const transforms = {};\r\n\r\n // create an object to hold the created site through\r\n // subsequent promise calls\r\n let model: IModel;\r\n\r\n // Create the \"siteModel\" from the template. Does not save the site item yet\r\n // Note: depending on licensing and user privs, will also create the team groups\r\n // and initiative item.\r\n return createStoryMapModelFromTemplate(\r\n template,\r\n templateDictionary,\r\n transforms,\r\n destinationAuthentication\r\n )\r\n .then(interpolated => {\r\n const options = {\r\n assets: interpolated.assets || []\r\n };\r\n return createStoryMap(\r\n interpolated,\r\n templateDictionary.folderId,\r\n options,\r\n destinationAuthentication\r\n );\r\n })\r\n .then(createdModel => {\r\n model = createdModel;\r\n // Update the template dictionary\r\n // TODO: This should be done in whatever receives\r\n // the outcome of this promise chain\r\n templateDictionary[template.itemId] = {\r\n itemId: model.item.id\r\n };\r\n // call the progress callback, which also mutates templateDictionary\r\n const finalStatus = itemProgressCallback(\r\n template.itemId,\r\n EItemProgressStatus.Finished,\r\n template.estimatedDeploymentCostFactor || 2,\r\n model.item.id\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: model.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 ...model\r\n },\r\n id: model.item.id,\r\n type: template.type,\r\n postProcess: false\r\n };\r\n response.item.itemId = model.item.id;\r\n return response;\r\n }\r\n })\r\n .catch(ex => {\r\n itemProgressCallback(template.itemId, EItemProgressStatus.Failed, 0);\r\n throw ex;\r\n });\r\n}\r\n\r\nexport function isAStoryMap(itemType: string): boolean {\r\n let result = false;\r\n if (itemType === \"StoryMap\") {\r\n result = true;\r\n }\r\n return result;\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 Story Map item types.\r\n *\r\n * @module storymap\r\n */\r\n\r\nimport * as common from \"@esri/solution-common\";\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n if (isAStoryMap(itemInfo.type, itemInfo.url)) {\r\n reject(common.fail(\"Classic StoryMap is not yet implemented\"));\r\n } else {\r\n reject(common.fail(itemInfo.id + \" is not a StoryMap\"));\r\n }\r\n });\r\n}\r\n\r\nexport function createItemFromTemplate(\r\n template: common.IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: common.UserSession,\r\n itemProgressCallback: common.IItemProgressCallback\r\n): Promise<common.ICreateItemFromTemplateResponse> {\r\n return new Promise<common.ICreateItemFromTemplateResponse>(resolve => {\r\n if (isAStoryMap(template.type, template.item.url)) {\r\n // Not yet implemented\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Failed,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type));\r\n } else {\r\n // Not valid\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Failed,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type));\r\n }\r\n });\r\n}\r\n\r\nexport function isAStoryMap(itemType: string, itemUrl?: string): boolean {\r\n if (itemUrl) {\r\n return [\r\n /\\/apps\\/Cascade\\//i,\r\n /\\/apps\\/MapJournal\\//i,\r\n /\\/apps\\/MapSeries\\//i,\r\n /\\/apps\\/MapTour\\//i,\r\n /\\/apps\\/Shortlist\\//i,\r\n /\\/apps\\/StoryMap\\//i,\r\n /\\/apps\\/StoryMapBasic\\//i,\r\n /\\/apps\\/StorytellingSwipe\\//i\r\n ].some(pattern => pattern.test(itemUrl));\r\n }\r\n return false;\r\n}\r\n"],"names":["getProp","createPlaceholderTemplate","propifyString","createId","cloneObject","normalizeSolutionTemplateItem","deepStringReplace","interpolate","serializeModel","createItem","interpolateItemId","stringToBlob","updateItem","failSafe","addItemResource","moveItem","convertItemToTemplate","getItemData","createItemFromTemplate","EItemProgressStatus","generateEmptyCreationResponse","removeItem","isAStoryMap","common"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;;;;;;;;;EAcG;EAIH;;;;;;;EAOG;EACa,SAAA,eAAe,CAAC,SAAA,GAAiB,EAAE,EAAA;MACjD,IAAI,aAAa,GAAG,CAAC,CAAC;EACtB,IAAA,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,KAAI;UAChD,IAAIA,iBAAO,CAAC,SAAS,EAAE,CAAA,EAAG,GAAG,CAAO,KAAA,CAAA,CAAC,KAAK,QAAQ,EAAE;EAClD,YAAA,IAAI,GAAG,KAAK,CAAS,MAAA,EAAA,aAAa,EAAE,EAAE;kBACpC,GAAG,CAAC,IAAI,CAAC;EACP,oBAAA,QAAQ,EAAE,GAAG;sBACb,OAAO,EAAE,CAAS,MAAA,EAAA,aAAa,CAAE,CAAA;EAClC,iBAAA,CAAC,CAAC;EACH,gBAAA,aAAa,EAAE,CAAC;EACjB,aAAA;EACF,SAAA;EACD,QAAA,OAAO,GAAG,CAAC;OACZ,EAAE,EAAE,CAAC,CAAC;EACT;;ECxCA;;;;;;;;;;;;;;EAcG;EAIH;;;;;EAKG;EACG,SAAU,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8B;EAC/B,SAAA,CAAC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;EAC1C,KAAA;EACD,IAAA,OAAO,KAAK,CAAC;EACf;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"storymap.umd.js","sources":["../../src/helpers/remap-webmap-keys.ts","../../src/helpers/get-storymap-dependencies.ts","../../src/helpers/convert-storymap-to-template.ts","../../src/helpers/get-portal-env.ts","../../src/helpers/get-storymap-subdomain.ts","../../src/helpers/get-storymap-base-url.ts","../../src/helpers/create-storymap-model-from-template.ts","../../src/helpers/create-storymap.ts","../../src/storymap-processor.ts","../../src/classic-storymap-processor.ts"],"sourcesContent":["/** @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\nimport { getProp } from \"@esri/hub-common\";\r\n\r\n/**\r\n * For some reason, the webmap resource key names are fancier than other resource keys\r\n * They look like this: r-<webmap-item-id>-<timestamp>\r\n * This interpolation is hard to accomplish given our current setup, so we're just overwriting\r\n * them with \"webmap0\", \"webmap1\" and so forth. This _seems_ to make no difference.\r\n *\r\n * @param model\r\n */\r\nexport function remapWebmapKeys(resources: any = {}): any[] {\r\n let webmapCounter = 0;\r\n return Object.keys(resources).reduce((acc, key) => {\r\n if (getProp(resources, `${key}.type`) === \"webmap\") {\r\n if (key !== `webmap${webmapCounter}`) {\r\n acc.push({\r\n original: key,\r\n updated: `webmap${webmapCounter}`\r\n });\r\n webmapCounter++;\r\n }\r\n }\r\n return 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\nimport { IModel, getProp } from \"@esri/hub-common\";\r\n\r\n/**\r\n * Extract a list of Items this storymap depends on\r\n * At this point we are just extracting webmaps\r\n *\r\n * @param model IModel\r\n */\r\nexport function getStoryMapDependencies(model: IModel): any[] {\r\n const resources = getProp(model, \"data.resources\") || {};\r\n return Object.keys(resources).reduce((acc, key) => {\r\n if (getProp(resources, `${key}.type`) === \"webmap\") {\r\n acc.push(getProp(resources, `${key}.data.itemId`));\r\n }\r\n return 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\nimport {\r\n IModel,\r\n cloneObject,\r\n propifyString,\r\n createId,\r\n normalizeSolutionTemplateItem,\r\n deepStringReplace\r\n} from \"@esri/hub-common\";\r\nimport { IItem } from \"@esri/arcgis-rest-portal\";\r\nimport {\r\n IItemTemplate,\r\n createPlaceholderTemplate\r\n} from \"@esri/solution-common\";\r\nimport { remapWebmapKeys } from \"./remap-webmap-keys\";\r\nimport { getStoryMapDependencies } from \"./get-storymap-dependencies\";\r\n\r\n/**\r\n * Convert a StoryMap IModel to an IItemTemplate\r\n *\r\n * @param model\r\n * @param authentication\r\n */\r\nexport function convertStoryMapToTemplate(\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\r\n tmpl.item.url = \"{{storyMapTemplateUrl}}\";\r\n\r\n // Storymap Webmap Resources have complex keys that we need to remap\r\n const webmapRemaps = remapWebmapKeys(tmpl.data.resources);\r\n // and then replace in the rest of the structure\r\n webmapRemaps.forEach(remap => {\r\n tmpl.data.resources[remap.updated] = cloneObject(\r\n tmpl.data.resources[remap.original]\r\n );\r\n delete tmpl.data.resources[remap.original];\r\n tmpl.data.nodes = deepStringReplace(\r\n tmpl.data.nodes,\r\n remap.original,\r\n remap.updated\r\n );\r\n });\r\n\r\n // use typeKeyword to mark item as published\r\n // Note: Hub team decided to discard unpublished drafts when creating a template\r\n const typeKeywords = tmpl.item.typeKeywords;\r\n if (typeKeywords.indexOf(unPublishedChangesKW) !== -1) {\r\n tmpl.item.typeKeywords = [publishedChangesKW].concat(\r\n tmpl.item.typeKeywords.filter(\r\n (word: string) => word !== unPublishedChangesKW\r\n )\r\n );\r\n }\r\n\r\n tmpl.properties = {};\r\n tmpl.properties.draftFileName = \"draft_{{timestamp}}.json\";\r\n Object.assign(tmpl.properties, oEmbedTemplates);\r\n\r\n tmpl.dependencies = getStoryMapDependencies(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, hubRequestOptions)\r\n // .then((response) => {\r\n // tmpl.resources = response.resources.map(e => e.resource)\r\n // // Don't directly copy oembed resources because we need to template these\r\n // // Also, discard draft version of the storymap itself\r\n // .filter(filename => !filename.includes('oembed') && filename.search(/draft_[0-9]+.json/) === -1);\r\n // return tmpl;\r\n // });\r\n}\r\n\r\n// Internal constants\r\nconst unPublishedChangesKW = \"smstatusunpublishedchanges\";\r\nconst publishedChangesKW = \"smstatuspublished\";\r\n\r\n/**\r\n * Template for oEmbed\r\n */\r\nconst oEmbedTemplates = {\r\n oembed: {\r\n version: \"1.0\",\r\n type: \"rich\",\r\n title: \"Example StoryMap\",\r\n url: \"{{storyMapTemplateUrl}}\",\r\n provider_name: \"ArcGIS StoryMaps\",\r\n provider_url: \"{{storyMapBaseUrl}}\",\r\n width: 800,\r\n height: 600,\r\n thumbnail_url: \"{{storyMapThumbnailUrl}}\",\r\n thumbnail_height: \"100.5\",\r\n thumbnail_width: \"400\",\r\n html:\r\n '<iframe src=\"{{storyMapTemplateUrl}}\" width=\"800\" height=\"600\" scrolling=\"yes\" frameborder=\"0\" allowfullscreen></iframe>',\r\n cache_age: 86400\r\n },\r\n oembedXML:\r\n '<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\\n <oembed>\\n <version>1.0</version>\\n <type>rich</type>\\n <title>Example StoryMap</title>\\n <url>{{storyMapTemplateUrl}}</url>\\n <author_name>undefined</author_name>\\n <provider_name>ArcGIS StoryMaps</provider_name>\\n <provider_url>{{storyMapBaseUrl}}</provider_url>\\n <width>800</width>\\n <height>600</height>\\n <thumbnail_url>{{storyMapThumbnailUrl}}</thumbnail_url>\\n <thumbnail_height>100.5</thumbnail_height>\\n <thumbnail_width>400</thumbnail_width>\\n <html><iframe src=\"{{storyMapTemplateUrl}}\" width=\"800\" height=\"600\" scrolling=\"yes\" frameborder=\"0\" allowfullscreen=\"true\"></iframe></html>\\n <cache_age>86400</cache_age>\\n </oembed>'\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\nexport function getPortalEnv(authentication: UserSession): string {\r\n const portalUrl =\r\n authentication.portal || \"https://www.arcgis.com/sharing/rest\";\r\n let result = \"portal\";\r\n if (portalUrl.match(/(qaext|\\.mapsqa)\\.arcgis.com/)) {\r\n result = \"qaext\";\r\n } else if (portalUrl.match(/(devext|\\.mapsdevext)\\.arcgis.com/)) {\r\n result = \"devext\";\r\n } else if (portalUrl.match(/(www|\\.maps)\\.arcgis.com/)) {\r\n result = \"www\";\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\n\r\nexport function getStoryMapSubdomain(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 storymaps on portal?\r\n let result;\r\n if (portalUrl.match(/(qaext|\\.mapsqa)\\.arcgis.com/)) {\r\n result = \"storymapsqa\";\r\n } else if (portalUrl.match(/(devext|\\.mapsdevext)\\.arcgis.com/)) {\r\n result = \"storymapsdev\";\r\n } else if (portalUrl.match(/(www|\\.maps)\\.arcgis.com/)) {\r\n result = \"storymaps\";\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 { getStoryMapSubdomain } from \"./get-storymap-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 getStoryMapBaseUrl(authentication: UserSession): string {\r\n let baseUrl = \"\";\r\n\r\n const subdomain = getStoryMapSubdomain(authentication);\r\n if (subdomain) {\r\n baseUrl = `https://${subdomain}.arcgis.com`;\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/storymaps`;\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\n * Given a template, process it and interpolate it such that\r\n * we have a model that is ready to be sent to the Portal API\r\n */\r\n\r\nimport { interpolate, IModelTemplate } from \"@esri/hub-common\";\r\nimport { UserSession } from \"@esri/solution-common\";\r\nimport { getPortalEnv } from \"./get-portal-env\";\r\nimport { getStoryMapBaseUrl } from \"./get-storymap-base-url\";\r\nimport { getStoryMapSubdomain } from \"./get-storymap-subdomain\";\r\n\r\nexport function createStoryMapModelFromTemplate(\r\n templateModel: IModelTemplate,\r\n settings: any,\r\n transforms: any,\r\n authentication: UserSession\r\n): Promise<any> {\r\n const timestamp = new Date().getTime();\r\n // Keep these around in case we encounter some old templates\r\n settings.agoenv = getPortalEnv(authentication);\r\n settings.smBase = getStoryMapSubdomain(authentication);\r\n settings.timestamp = new Date().getTime();\r\n // These are used in the oembed resource, as well as the item url\r\n // they have `{{appid}}` in them so that the id of the created item\r\n // will be interpolated into it after the item is created\r\n settings.storyMapBaseUrl = getStoryMapBaseUrl(authentication);\r\n settings.storyMapTemplateUrl = `${settings.storyMapBaseUrl}/stories/{{appid}}`;\r\n settings.storyMapThumnailUrl = `${authentication.portal}/content/items/{{appid}}/info/thumbnail/thumbnail.jpg/?w=400&d=${timestamp}`;\r\n\r\n const model = interpolate(templateModel, settings, transforms);\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\n\r\n// TODO ENSURE THIS CREATES IN THE TARGET FOLDER\r\nimport {\r\n IModel,\r\n failSafe,\r\n serializeModel,\r\n interpolateItemId,\r\n stringToBlob\r\n} from \"@esri/hub-common\";\r\n\r\nimport { UserSession } from \"@esri/solution-common\";\r\n\r\nimport {\r\n createItem,\r\n moveItem,\r\n addItemResource,\r\n updateItem,\r\n ICreateItemOptions,\r\n ICreateItemResponse\r\n} from \"@esri/arcgis-rest-portal\";\r\n\r\n/**\r\n * Create a StoryMap from an interpolated template\r\n *\r\n * @param model\r\n * @param options\r\n * @param authentication\r\n */\r\nexport function createStoryMap(\r\n model: IModel,\r\n folderId: string,\r\n options: any,\r\n authentication: UserSession\r\n): Promise<IModel> {\r\n // create an array to hold well-known resources\r\n // that we have to generate from the passed in model\r\n const resources: any[] = [];\r\n\r\n // For unknown 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 createItem(createOptions)\r\n .then((createResponse: ICreateItemResponse) => {\r\n // hold the id in the model\r\n model.item.id = createResponse.id;\r\n // and re-interpolate the item id\r\n model = interpolateItemId(model);\r\n // Compute the item url based on current environment\r\n\r\n // Storymaps store draft data in a timestamped resource attached to the item\r\n // We'll just use the published data for the first \"draft\"\r\n resources.push({\r\n name: model.properties.draftFileName,\r\n file: stringToBlob(JSON.stringify(model.data))\r\n });\r\n resources.push({\r\n name: \"oembed.json\",\r\n file: stringToBlob(JSON.stringify(model.properties.oembed))\r\n });\r\n resources.push({\r\n name: \"oembed.xml\",\r\n file: stringToBlob(model.properties.oembedXML)\r\n });\r\n // remove the properties hash now that we've gotten what we need\r\n delete model.properties;\r\n // update the item with the newly re-interpolated model\r\n return Promise.all([\r\n updateItem({\r\n item: serializeModel(model),\r\n authentication\r\n }),\r\n authentication.getUsername()\r\n ]);\r\n })\r\n .then((responses: any[]) => {\r\n const username = responses[1];\r\n // add the resources\r\n const failSafeAddItemResource = failSafe(addItemResource, {\r\n success: true\r\n });\r\n const resourcePromises = resources.map(resource => {\r\n return failSafeAddItemResource({\r\n id: model.item.id,\r\n owner: username,\r\n resource: resource.file,\r\n name: resource.name,\r\n authentication\r\n });\r\n });\r\n // Fire and forget as these are not critical-path\r\n return Promise.all(resourcePromises);\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","/** @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 Story Map item types.\r\n *\r\n * @module storymap\r\n */\r\n\r\nimport {\r\n IItemTemplate,\r\n IItemProgressCallback,\r\n ICreateItemFromTemplateResponse,\r\n EItemProgressStatus,\r\n UserSession,\r\n generateEmptyCreationResponse\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 { convertStoryMapToTemplate } from \"./helpers/convert-storymap-to-template\";\r\nimport { createStoryMapModelFromTemplate } from \"./helpers/create-storymap-model-from-template\";\r\nimport { createStoryMap } from \"./helpers/create-storymap\";\r\n\r\n/**\r\n * Convert a StoryMap to 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 */\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 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 })\r\n .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 convertStoryMapToTemplate(model);\r\n })\r\n .then(tmpl => {\r\n return tmpl;\r\n });\r\n}\r\n\r\n/**\r\n * Create a StoryMap from the passed in 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 // ensure we have a solution object in the templateDictionary hash\r\n if (!templateDictionary.solution) {\r\n templateDictionary.solution = {};\r\n }\r\n // .title should always be set on the templateDictionary\r\n templateDictionary.solution.title = templateDictionary.title;\r\n\r\n // TODO: Determine if we need any transforms in this new env\r\n const transforms = {};\r\n\r\n // create an object to hold the created site through\r\n // subsequent promise calls\r\n let model: IModel;\r\n\r\n // Create the \"siteModel\" from the template. Does not save the site item yet\r\n // Note: depending on licensing and user privs, will also create the team groups\r\n // and initiative item.\r\n return createStoryMapModelFromTemplate(\r\n template,\r\n templateDictionary,\r\n transforms,\r\n destinationAuthentication\r\n )\r\n .then(interpolated => {\r\n const options = {\r\n assets: interpolated.assets || []\r\n };\r\n return createStoryMap(\r\n interpolated,\r\n templateDictionary.folderId,\r\n options,\r\n destinationAuthentication\r\n );\r\n })\r\n .then(createdModel => {\r\n model = createdModel;\r\n // Update the template dictionary\r\n // TODO: This should be done in whatever receives\r\n // the outcome of this promise chain\r\n templateDictionary[template.itemId] = {\r\n itemId: model.item.id\r\n };\r\n // call the progress callback, which also mutates templateDictionary\r\n const finalStatus = itemProgressCallback(\r\n template.itemId,\r\n EItemProgressStatus.Finished,\r\n template.estimatedDeploymentCostFactor || 2,\r\n model.item.id\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: model.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 ...model\r\n },\r\n id: model.item.id,\r\n type: template.type,\r\n postProcess: false\r\n };\r\n response.item.itemId = model.item.id;\r\n return response;\r\n }\r\n })\r\n .catch(ex => {\r\n itemProgressCallback(template.itemId, EItemProgressStatus.Failed, 0);\r\n throw ex;\r\n });\r\n}\r\n\r\nexport function isAStoryMap(itemType: string): boolean {\r\n let result = false;\r\n if (itemType === \"StoryMap\") {\r\n result = true;\r\n }\r\n return result;\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 Story Map item types.\r\n *\r\n * @module storymap\r\n */\r\n\r\nimport * as common from \"@esri/solution-common\";\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n if (isAStoryMap(itemInfo.type, itemInfo.url)) {\r\n reject(common.fail(\"Classic StoryMap is not yet implemented\"));\r\n } else {\r\n reject(common.fail(itemInfo.id + \" is not a StoryMap\"));\r\n }\r\n });\r\n}\r\n\r\nexport function createItemFromTemplate(\r\n template: common.IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: common.UserSession,\r\n itemProgressCallback: common.IItemProgressCallback\r\n): Promise<common.ICreateItemFromTemplateResponse> {\r\n return new Promise<common.ICreateItemFromTemplateResponse>(resolve => {\r\n if (isAStoryMap(template.type, template.item.url)) {\r\n // Not yet implemented\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Failed,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type));\r\n } else {\r\n // Not valid\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Failed,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type));\r\n }\r\n });\r\n}\r\n\r\nexport function isAStoryMap(itemType: string, itemUrl?: string): boolean {\r\n if (itemUrl) {\r\n return [\r\n /\\/apps\\/Cascade\\//i,\r\n /\\/apps\\/MapJournal\\//i,\r\n /\\/apps\\/MapSeries\\//i,\r\n /\\/apps\\/MapTour\\//i,\r\n /\\/apps\\/Shortlist\\//i,\r\n /\\/apps\\/StoryMap\\//i,\r\n /\\/apps\\/StoryMapBasic\\//i,\r\n /\\/apps\\/StorytellingSwipe\\//i\r\n ].some(pattern => pattern.test(itemUrl));\r\n }\r\n return false;\r\n}\r\n"],"names":["getProp","createPlaceholderTemplate","propifyString","createId","cloneObject","normalizeSolutionTemplateItem","deepStringReplace","interpolate","serializeModel","createItem","interpolateItemId","stringToBlob","updateItem","failSafe","addItemResource","moveItem","convertItemToTemplate","getItemData","createItemFromTemplate","EItemProgressStatus","generateEmptyCreationResponse","removeItem","isAStoryMap","common"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;;;;;;;;;;EAkBA;;;;;;;;WAQgB,eAAe,CAAC,YAAiB,EAAE;MACjD,IAAI,aAAa,GAAG,CAAC,CAAC;MACtB,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG;UAC5C,IAAIA,iBAAO,CAAC,SAAS,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,QAAQ,EAAE;cAClD,IAAI,GAAG,KAAK,SAAS,aAAa,EAAE,EAAE;kBACpC,GAAG,CAAC,IAAI,CAAC;sBACP,QAAQ,EAAE,GAAG;sBACb,OAAO,EAAE,SAAS,aAAa,EAAE;mBAClC,CAAC,CAAC;kBACH,aAAa,EAAE,CAAC;eACjB;WACF;UACD,OAAO,GAAG,CAAC;OACZ,EAAE,EAAE,CAAC,CAAC;EACT;;ECxCA;;;;;;;;;;;;;;;EAkBA;;;;;;WAMgB,uBAAuB,CAAC,KAAa;MACnD,MAAM,SAAS,GAAGA,iBAAO,CAAC,KAAK,EAAE,gBAAgB,CAAC,IAAI,EAAE,CAAC;MACzD,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG;UAC5C,IAAIA,iBAAO,CAAC,SAAS,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,QAAQ,EAAE;cAClD,GAAG,CAAC,IAAI,CAACA,iBAAO,CAAC,SAAS,EAAE,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC;WACpD;UACD,OAAO,GAAG,CAAC;OACZ,EAAE,EAAE,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WAAW,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;;cAEjD,oBAAoB,CAClB,QAAQ,CAAC,MAAM,EACfA,iBAAM,CAAC,mBAAmB,CAAC,MAAM,EACjC,CAAC,CACF,CAAC;cACF,OAAO,CAACA,iBAAM,CAAC,6BAA6B,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;WAC9D;eAAM;;cAEL,oBAAoB,CAClB,QAAQ,CAAC,MAAM,EACfA,iBAAM,CAAC,mBAAmB,CAAC,MAAM,EACjC,CAAC,CACF,CAAC;cACF,OAAO,CAACA,iBAAM,CAAC,6BAA6B,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;WAC9D;OACF,CAAC,CAAC;EACL,CAAC;WAEe,WAAW,CAAC,QAAgB,EAAE,OAAgB;MAC5D,IAAI,OAAO,EAAE;UACX,OAAO;cACL,oBAAoB;cACpB,uBAAuB;cACvB,sBAAsB;cACtB,oBAAoB;cACpB,sBAAsB;cACtB,qBAAqB;cACrB,0BAA0B;cAC1B,8BAA8B;WAC/B,CAAC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;OAC1C;MACD,OAAO,KAAK,CAAC;EACf;;;;;;;;;;;;;;;;;;"}
@@ -1,7 +1,7 @@
1
1
  /* @preserve
2
- * @esri/solution-storymap - v1.3.13 - Apache-2.0
2
+ * @esri/solution-storymap - v1.3.16 - Apache-2.0
3
3
  * Copyright (c) 2018-2022 Esri, Inc.
4
- * Tue Apr 26 2022 15:04:03 GMT-0700 (Pacific Daylight Time)
4
+ * Wed Jun 08 2022 10:59:31 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.
@@ -1 +1 @@
1
- {"version":3,"file":"storymap.umd.min.js","sources":["../../src/helpers/convert-storymap-to-template.ts","../../src/helpers/remap-webmap-keys.ts","../../src/helpers/get-storymap-dependencies.ts","../../src/helpers/get-storymap-subdomain.ts","../../src/helpers/create-storymap-model-from-template.ts","../../src/helpers/get-portal-env.ts","../../src/helpers/get-storymap-base-url.ts","../../src/storymap-processor.ts","../../src/helpers/create-storymap.ts","../../src/classic-storymap-processor.ts"],"sourcesContent":["/** @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\nimport {\r\n IModel,\r\n cloneObject,\r\n propifyString,\r\n createId,\r\n normalizeSolutionTemplateItem,\r\n deepStringReplace\r\n} from \"@esri/hub-common\";\r\nimport { IItem } from \"@esri/arcgis-rest-portal\";\r\nimport {\r\n IItemTemplate,\r\n createPlaceholderTemplate\r\n} from \"@esri/solution-common\";\r\nimport { remapWebmapKeys } from \"./remap-webmap-keys\";\r\nimport { getStoryMapDependencies } from \"./get-storymap-dependencies\";\r\n\r\n/**\r\n * Convert a StoryMap IModel to an IItemTemplate\r\n *\r\n * @param model\r\n * @param authentication\r\n */\r\nexport function convertStoryMapToTemplate(\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\r\n tmpl.item.url = \"{{storyMapTemplateUrl}}\";\r\n\r\n // Storymap Webmap Resources have complex keys that we need to remap\r\n const webmapRemaps = remapWebmapKeys(tmpl.data.resources);\r\n // and then replace in the rest of the structure\r\n webmapRemaps.forEach(remap => {\r\n tmpl.data.resources[remap.updated] = cloneObject(\r\n tmpl.data.resources[remap.original]\r\n );\r\n delete tmpl.data.resources[remap.original];\r\n tmpl.data.nodes = deepStringReplace(\r\n tmpl.data.nodes,\r\n remap.original,\r\n remap.updated\r\n );\r\n });\r\n\r\n // use typeKeyword to mark item as published\r\n // Note: Hub team decided to discard unpublished drafts when creating a template\r\n const typeKeywords = tmpl.item.typeKeywords;\r\n if (typeKeywords.indexOf(unPublishedChangesKW) !== -1) {\r\n tmpl.item.typeKeywords = [publishedChangesKW].concat(\r\n tmpl.item.typeKeywords.filter(\r\n (word: string) => word !== unPublishedChangesKW\r\n )\r\n );\r\n }\r\n\r\n tmpl.properties = {};\r\n tmpl.properties.draftFileName = \"draft_{{timestamp}}.json\";\r\n Object.assign(tmpl.properties, oEmbedTemplates);\r\n\r\n tmpl.dependencies = getStoryMapDependencies(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, hubRequestOptions)\r\n // .then((response) => {\r\n // tmpl.resources = response.resources.map(e => e.resource)\r\n // // Don't directly copy oembed resources because we need to template these\r\n // // Also, discard draft version of the storymap itself\r\n // .filter(filename => !filename.includes('oembed') && filename.search(/draft_[0-9]+.json/) === -1);\r\n // return tmpl;\r\n // });\r\n}\r\n\r\n// Internal constants\r\nconst unPublishedChangesKW = \"smstatusunpublishedchanges\";\r\nconst publishedChangesKW = \"smstatuspublished\";\r\n\r\n/**\r\n * Template for oEmbed\r\n */\r\nconst oEmbedTemplates = {\r\n oembed: {\r\n version: \"1.0\",\r\n type: \"rich\",\r\n title: \"Example StoryMap\",\r\n url: \"{{storyMapTemplateUrl}}\",\r\n provider_name: \"ArcGIS StoryMaps\",\r\n provider_url: \"{{storyMapBaseUrl}}\",\r\n width: 800,\r\n height: 600,\r\n thumbnail_url: \"{{storyMapThumbnailUrl}}\",\r\n thumbnail_height: \"100.5\",\r\n thumbnail_width: \"400\",\r\n html:\r\n '<iframe src=\"{{storyMapTemplateUrl}}\" width=\"800\" height=\"600\" scrolling=\"yes\" frameborder=\"0\" allowfullscreen></iframe>',\r\n cache_age: 86400\r\n },\r\n oembedXML:\r\n '<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\\n <oembed>\\n <version>1.0</version>\\n <type>rich</type>\\n <title>Example StoryMap</title>\\n <url>{{storyMapTemplateUrl}}</url>\\n <author_name>undefined</author_name>\\n <provider_name>ArcGIS StoryMaps</provider_name>\\n <provider_url>{{storyMapBaseUrl}}</provider_url>\\n <width>800</width>\\n <height>600</height>\\n <thumbnail_url>{{storyMapThumbnailUrl}}</thumbnail_url>\\n <thumbnail_height>100.5</thumbnail_height>\\n <thumbnail_width>400</thumbnail_width>\\n <html><iframe src=\"{{storyMapTemplateUrl}}\" width=\"800\" height=\"600\" scrolling=\"yes\" frameborder=\"0\" allowfullscreen=\"true\"></iframe></html>\\n <cache_age>86400</cache_age>\\n </oembed>'\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\nimport { getProp } from \"@esri/hub-common\";\r\n\r\n/**\r\n * For some reason, the webmap resource key names are fancier than other resource keys\r\n * They look like this: r-<webmap-item-id>-<timestamp>\r\n * This interpolation is hard to accomplish given our current setup, so we're just overwriting\r\n * them with \"webmap0\", \"webmap1\" and so forth. This _seems_ to make no difference.\r\n *\r\n * @param model\r\n */\r\nexport function remapWebmapKeys(resources: any = {}): any[] {\r\n let webmapCounter = 0;\r\n return Object.keys(resources).reduce((acc, key) => {\r\n if (getProp(resources, `${key}.type`) === \"webmap\") {\r\n if (key !== `webmap${webmapCounter}`) {\r\n acc.push({\r\n original: key,\r\n updated: `webmap${webmapCounter}`\r\n });\r\n webmapCounter++;\r\n }\r\n }\r\n return 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\nimport { IModel, getProp } from \"@esri/hub-common\";\r\n\r\n/**\r\n * Extract a list of Items this storymap depends on\r\n * At this point we are just extracting webmaps\r\n *\r\n * @param model IModel\r\n */\r\nexport function getStoryMapDependencies(model: IModel): any[] {\r\n const resources = getProp(model, \"data.resources\") || {};\r\n return Object.keys(resources).reduce((acc, key) => {\r\n if (getProp(resources, `${key}.type`) === \"webmap\") {\r\n acc.push(getProp(resources, `${key}.data.itemId`));\r\n }\r\n return 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\nimport { UserSession } from \"@esri/solution-common\";\r\n\r\nexport function getStoryMapSubdomain(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 storymaps on portal?\r\n let result;\r\n if (portalUrl.match(/(qaext|\\.mapsqa)\\.arcgis.com/)) {\r\n result = \"storymapsqa\";\r\n } else if (portalUrl.match(/(devext|\\.mapsdevext)\\.arcgis.com/)) {\r\n result = \"storymapsdev\";\r\n } else if (portalUrl.match(/(www|\\.maps)\\.arcgis.com/)) {\r\n result = \"storymaps\";\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\n/**\r\n * Given a template, process it and interpolate it such that\r\n * we have a model that is ready to be sent to the Portal API\r\n */\r\n\r\nimport { interpolate, IModelTemplate } from \"@esri/hub-common\";\r\nimport { UserSession } from \"@esri/solution-common\";\r\nimport { getPortalEnv } from \"./get-portal-env\";\r\nimport { getStoryMapBaseUrl } from \"./get-storymap-base-url\";\r\nimport { getStoryMapSubdomain } from \"./get-storymap-subdomain\";\r\n\r\nexport function createStoryMapModelFromTemplate(\r\n templateModel: IModelTemplate,\r\n settings: any,\r\n transforms: any,\r\n authentication: UserSession\r\n): Promise<any> {\r\n const timestamp = new Date().getTime();\r\n // Keep these around in case we encounter some old templates\r\n settings.agoenv = getPortalEnv(authentication);\r\n settings.smBase = getStoryMapSubdomain(authentication);\r\n settings.timestamp = new Date().getTime();\r\n // These are used in the oembed resource, as well as the item url\r\n // they have `{{appid}}` in them so that the id of the created item\r\n // will be interpolated into it after the item is created\r\n settings.storyMapBaseUrl = getStoryMapBaseUrl(authentication);\r\n settings.storyMapTemplateUrl = `${settings.storyMapBaseUrl}/stories/{{appid}}`;\r\n settings.storyMapThumnailUrl = `${authentication.portal}/content/items/{{appid}}/info/thumbnail/thumbnail.jpg/?w=400&d=${timestamp}`;\r\n\r\n const model = interpolate(templateModel, settings, transforms);\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\n\r\nexport function getPortalEnv(authentication: UserSession): string {\r\n const portalUrl =\r\n authentication.portal || \"https://www.arcgis.com/sharing/rest\";\r\n let result = \"portal\";\r\n if (portalUrl.match(/(qaext|\\.mapsqa)\\.arcgis.com/)) {\r\n result = \"qaext\";\r\n } else if (portalUrl.match(/(devext|\\.mapsdevext)\\.arcgis.com/)) {\r\n result = \"devext\";\r\n } else if (portalUrl.match(/(www|\\.maps)\\.arcgis.com/)) {\r\n result = \"www\";\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 { getStoryMapSubdomain } from \"./get-storymap-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 getStoryMapBaseUrl(authentication: UserSession): string {\r\n let baseUrl = \"\";\r\n\r\n const subdomain = getStoryMapSubdomain(authentication);\r\n if (subdomain) {\r\n baseUrl = `https://${subdomain}.arcgis.com`;\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/storymaps`;\r\n }\r\n\r\n return baseUrl;\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 Story Map item types.\r\n *\r\n * @module storymap\r\n */\r\n\r\nimport {\r\n IItemTemplate,\r\n IItemProgressCallback,\r\n ICreateItemFromTemplateResponse,\r\n EItemProgressStatus,\r\n UserSession,\r\n generateEmptyCreationResponse\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 { convertStoryMapToTemplate } from \"./helpers/convert-storymap-to-template\";\r\nimport { createStoryMapModelFromTemplate } from \"./helpers/create-storymap-model-from-template\";\r\nimport { createStoryMap } from \"./helpers/create-storymap\";\r\n\r\n/**\r\n * Convert a StoryMap to 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 */\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 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 })\r\n .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 convertStoryMapToTemplate(model);\r\n })\r\n .then(tmpl => {\r\n return tmpl;\r\n });\r\n}\r\n\r\n/**\r\n * Create a StoryMap from the passed in 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 // ensure we have a solution object in the templateDictionary hash\r\n if (!templateDictionary.solution) {\r\n templateDictionary.solution = {};\r\n }\r\n // .title should always be set on the templateDictionary\r\n templateDictionary.solution.title = templateDictionary.title;\r\n\r\n // TODO: Determine if we need any transforms in this new env\r\n const transforms = {};\r\n\r\n // create an object to hold the created site through\r\n // subsequent promise calls\r\n let model: IModel;\r\n\r\n // Create the \"siteModel\" from the template. Does not save the site item yet\r\n // Note: depending on licensing and user privs, will also create the team groups\r\n // and initiative item.\r\n return createStoryMapModelFromTemplate(\r\n template,\r\n templateDictionary,\r\n transforms,\r\n destinationAuthentication\r\n )\r\n .then(interpolated => {\r\n const options = {\r\n assets: interpolated.assets || []\r\n };\r\n return createStoryMap(\r\n interpolated,\r\n templateDictionary.folderId,\r\n options,\r\n destinationAuthentication\r\n );\r\n })\r\n .then(createdModel => {\r\n model = createdModel;\r\n // Update the template dictionary\r\n // TODO: This should be done in whatever receives\r\n // the outcome of this promise chain\r\n templateDictionary[template.itemId] = {\r\n itemId: model.item.id\r\n };\r\n // call the progress callback, which also mutates templateDictionary\r\n const finalStatus = itemProgressCallback(\r\n template.itemId,\r\n EItemProgressStatus.Finished,\r\n template.estimatedDeploymentCostFactor || 2,\r\n model.item.id\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: model.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 ...model\r\n },\r\n id: model.item.id,\r\n type: template.type,\r\n postProcess: false\r\n };\r\n response.item.itemId = model.item.id;\r\n return response;\r\n }\r\n })\r\n .catch(ex => {\r\n itemProgressCallback(template.itemId, EItemProgressStatus.Failed, 0);\r\n throw ex;\r\n });\r\n}\r\n\r\nexport function isAStoryMap(itemType: string): boolean {\r\n let result = false;\r\n if (itemType === \"StoryMap\") {\r\n result = true;\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\n\r\n// TODO ENSURE THIS CREATES IN THE TARGET FOLDER\r\nimport {\r\n IModel,\r\n failSafe,\r\n serializeModel,\r\n interpolateItemId,\r\n stringToBlob\r\n} from \"@esri/hub-common\";\r\n\r\nimport { UserSession } from \"@esri/solution-common\";\r\n\r\nimport {\r\n createItem,\r\n moveItem,\r\n addItemResource,\r\n updateItem,\r\n ICreateItemOptions,\r\n ICreateItemResponse\r\n} from \"@esri/arcgis-rest-portal\";\r\n\r\n/**\r\n * Create a StoryMap from an interpolated template\r\n *\r\n * @param model\r\n * @param options\r\n * @param authentication\r\n */\r\nexport function createStoryMap(\r\n model: IModel,\r\n folderId: string,\r\n options: any,\r\n authentication: UserSession\r\n): Promise<IModel> {\r\n // create an array to hold well-known resources\r\n // that we have to generate from the passed in model\r\n const resources: any[] = [];\r\n\r\n // For unknown 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 createItem(createOptions)\r\n .then((createResponse: ICreateItemResponse) => {\r\n // hold the id in the model\r\n model.item.id = createResponse.id;\r\n // and re-interpolate the item id\r\n model = interpolateItemId(model);\r\n // Compute the item url based on current environment\r\n\r\n // Storymaps store draft data in a timestamped resource attached to the item\r\n // We'll just use the published data for the first \"draft\"\r\n resources.push({\r\n name: model.properties.draftFileName,\r\n file: stringToBlob(JSON.stringify(model.data))\r\n });\r\n resources.push({\r\n name: \"oembed.json\",\r\n file: stringToBlob(JSON.stringify(model.properties.oembed))\r\n });\r\n resources.push({\r\n name: \"oembed.xml\",\r\n file: stringToBlob(model.properties.oembedXML)\r\n });\r\n // remove the properties hash now that we've gotten what we need\r\n delete model.properties;\r\n // update the item with the newly re-interpolated model\r\n return Promise.all([\r\n updateItem({\r\n item: serializeModel(model),\r\n authentication\r\n }),\r\n authentication.getUsername()\r\n ]);\r\n })\r\n .then((responses: any[]) => {\r\n const username = responses[1];\r\n // add the resources\r\n const failSafeAddItemResource = failSafe(addItemResource, {\r\n success: true\r\n });\r\n const resourcePromises = resources.map(resource => {\r\n return failSafeAddItemResource({\r\n id: model.item.id,\r\n owner: username,\r\n resource: resource.file,\r\n name: resource.name,\r\n authentication\r\n });\r\n });\r\n // Fire and forget as these are not critical-path\r\n return Promise.all(resourcePromises);\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","/** @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 Story Map item types.\r\n *\r\n * @module storymap\r\n */\r\n\r\nimport * as common from \"@esri/solution-common\";\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n if (isAStoryMap(itemInfo.type, itemInfo.url)) {\r\n reject(common.fail(\"Classic StoryMap is not yet implemented\"));\r\n } else {\r\n reject(common.fail(itemInfo.id + \" is not a StoryMap\"));\r\n }\r\n });\r\n}\r\n\r\nexport function createItemFromTemplate(\r\n template: common.IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: common.UserSession,\r\n itemProgressCallback: common.IItemProgressCallback\r\n): Promise<common.ICreateItemFromTemplateResponse> {\r\n return new Promise<common.ICreateItemFromTemplateResponse>(resolve => {\r\n if (isAStoryMap(template.type, template.item.url)) {\r\n // Not yet implemented\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Failed,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type));\r\n } else {\r\n // Not valid\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Failed,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type));\r\n }\r\n });\r\n}\r\n\r\nexport function isAStoryMap(itemType: string, itemUrl?: string): boolean {\r\n if (itemUrl) {\r\n return [\r\n /\\/apps\\/Cascade\\//i,\r\n /\\/apps\\/MapJournal\\//i,\r\n /\\/apps\\/MapSeries\\//i,\r\n /\\/apps\\/MapTour\\//i,\r\n /\\/apps\\/Shortlist\\//i,\r\n /\\/apps\\/StoryMap\\//i,\r\n /\\/apps\\/StoryMapBasic\\//i,\r\n /\\/apps\\/StorytellingSwipe\\//i\r\n ].some(pattern => pattern.test(itemUrl));\r\n }\r\n return false;\r\n}\r\n"],"names":["convertStoryMapToTemplate","model","tmpl","createPlaceholderTemplate","item","id","type","key","propifyString","title","createId","clone","cloneObject","data","created","modified","normalizeSolutionTemplateItem","url","resources","webmapCounter","Object","keys","reduce","acc","getProp","push","original","updated","remapWebmapKeys","forEach","remap","nodes","deepStringReplace","typeKeywords","indexOf","unPublishedChangesKW","publishedChangesKW","concat","filter","word","properties","draftFileName","assign","oEmbedTemplates","dependencies","getStoryMapDependencies","Promise","resolve","oembed","version","provider_name","provider_url","width","height","thumbnail_url","thumbnail_height","thumbnail_width","html","cache_age","oembedXML","getStoryMapSubdomain","authentication","portalUrl","portal","result","match","createStoryMapModelFromTemplate","templateModel","settings","transforms","timestamp","Date","getTime","agoenv","getPortalEnv","smBase","storyMapBaseUrl","baseUrl","subdomain","replace","getStoryMapBaseUrl","storyMapTemplateUrl","storyMapThumnailUrl","interpolate","solutionItemId","itemInfo","destAuthentication","srcAuthentication","getItemData","then","template","templateDictionary","destinationAuthentication","itemProgressCallback","itemId","EItemProgressStatus","Started","generateEmptyCreationResponse","solution","interpolated","assets","folderId","options","createOptions","serializeModel","thumbnail","params","createItem","createResponse","interpolateItemId","name","file","stringToBlob","JSON","stringify","all","updateItem","getUsername","responses","username","failSafeAddItemResource","failSafe","addItemResource","success","resourcePromises","map","resource","owner","moveItem","createStoryMap","createdModel","Finished","estimatedDeploymentCostFactor","response","postProcess","removeItem","failSafeRemove","catch","ex","Failed","itemType","isAStoryMap","itemUrl","some","pattern","test","reject","common","fail"],"mappings":";;;;;;;;;;;;;;;;;ywBAsCM,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,EAGrBb,EAAKE,KAAKa,IAAM,2BC7BF,SAAgBC,EAAiB,IAC/C,IAAIC,EAAgB,EACpB,OAAOC,OAAOC,KAAKH,GAAWI,QAAO,CAACC,EAAKhB,KACC,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AStF,KAAKa,KAE3C4E,EACEH,EAASI,OACTqD,EAAOpD,oBAAoB4C,OAC3B,GAEF5F,EAAQoG,EAAOlD,8BAA8BP,EAASpF"}
1
+ {"version":3,"file":"storymap.umd.min.js","sources":["../../src/helpers/convert-storymap-to-template.ts","../../src/helpers/remap-webmap-keys.ts","../../src/helpers/get-storymap-dependencies.ts","../../src/helpers/get-storymap-subdomain.ts","../../src/helpers/create-storymap-model-from-template.ts","../../src/helpers/get-portal-env.ts","../../src/helpers/get-storymap-base-url.ts","../../src/storymap-processor.ts","../../src/helpers/create-storymap.ts","../../src/classic-storymap-processor.ts"],"sourcesContent":["/** @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\nimport {\r\n IModel,\r\n cloneObject,\r\n propifyString,\r\n createId,\r\n normalizeSolutionTemplateItem,\r\n deepStringReplace\r\n} from \"@esri/hub-common\";\r\nimport { IItem } from \"@esri/arcgis-rest-portal\";\r\nimport {\r\n IItemTemplate,\r\n createPlaceholderTemplate\r\n} from \"@esri/solution-common\";\r\nimport { remapWebmapKeys } from \"./remap-webmap-keys\";\r\nimport { getStoryMapDependencies } from \"./get-storymap-dependencies\";\r\n\r\n/**\r\n * Convert a StoryMap IModel to an IItemTemplate\r\n *\r\n * @param model\r\n * @param authentication\r\n */\r\nexport function convertStoryMapToTemplate(\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\r\n tmpl.item.url = \"{{storyMapTemplateUrl}}\";\r\n\r\n // Storymap Webmap Resources have complex keys that we need to remap\r\n const webmapRemaps = remapWebmapKeys(tmpl.data.resources);\r\n // and then replace in the rest of the structure\r\n webmapRemaps.forEach(remap => {\r\n tmpl.data.resources[remap.updated] = cloneObject(\r\n tmpl.data.resources[remap.original]\r\n );\r\n delete tmpl.data.resources[remap.original];\r\n tmpl.data.nodes = deepStringReplace(\r\n tmpl.data.nodes,\r\n remap.original,\r\n remap.updated\r\n );\r\n });\r\n\r\n // use typeKeyword to mark item as published\r\n // Note: Hub team decided to discard unpublished drafts when creating a template\r\n const typeKeywords = tmpl.item.typeKeywords;\r\n if (typeKeywords.indexOf(unPublishedChangesKW) !== -1) {\r\n tmpl.item.typeKeywords = [publishedChangesKW].concat(\r\n tmpl.item.typeKeywords.filter(\r\n (word: string) => word !== unPublishedChangesKW\r\n )\r\n );\r\n }\r\n\r\n tmpl.properties = {};\r\n tmpl.properties.draftFileName = \"draft_{{timestamp}}.json\";\r\n Object.assign(tmpl.properties, oEmbedTemplates);\r\n\r\n tmpl.dependencies = getStoryMapDependencies(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, hubRequestOptions)\r\n // .then((response) => {\r\n // tmpl.resources = response.resources.map(e => e.resource)\r\n // // Don't directly copy oembed resources because we need to template these\r\n // // Also, discard draft version of the storymap itself\r\n // .filter(filename => !filename.includes('oembed') && filename.search(/draft_[0-9]+.json/) === -1);\r\n // return tmpl;\r\n // });\r\n}\r\n\r\n// Internal constants\r\nconst unPublishedChangesKW = \"smstatusunpublishedchanges\";\r\nconst publishedChangesKW = \"smstatuspublished\";\r\n\r\n/**\r\n * Template for oEmbed\r\n */\r\nconst oEmbedTemplates = {\r\n oembed: {\r\n version: \"1.0\",\r\n type: \"rich\",\r\n title: \"Example StoryMap\",\r\n url: \"{{storyMapTemplateUrl}}\",\r\n provider_name: \"ArcGIS StoryMaps\",\r\n provider_url: \"{{storyMapBaseUrl}}\",\r\n width: 800,\r\n height: 600,\r\n thumbnail_url: \"{{storyMapThumbnailUrl}}\",\r\n thumbnail_height: \"100.5\",\r\n thumbnail_width: \"400\",\r\n html:\r\n '<iframe src=\"{{storyMapTemplateUrl}}\" width=\"800\" height=\"600\" scrolling=\"yes\" frameborder=\"0\" allowfullscreen></iframe>',\r\n cache_age: 86400\r\n },\r\n oembedXML:\r\n '<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\\n <oembed>\\n <version>1.0</version>\\n <type>rich</type>\\n <title>Example StoryMap</title>\\n <url>{{storyMapTemplateUrl}}</url>\\n <author_name>undefined</author_name>\\n <provider_name>ArcGIS StoryMaps</provider_name>\\n <provider_url>{{storyMapBaseUrl}}</provider_url>\\n <width>800</width>\\n <height>600</height>\\n <thumbnail_url>{{storyMapThumbnailUrl}}</thumbnail_url>\\n <thumbnail_height>100.5</thumbnail_height>\\n <thumbnail_width>400</thumbnail_width>\\n <html><iframe src=\"{{storyMapTemplateUrl}}\" width=\"800\" height=\"600\" scrolling=\"yes\" frameborder=\"0\" allowfullscreen=\"true\"></iframe></html>\\n <cache_age>86400</cache_age>\\n </oembed>'\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\nimport { getProp } from \"@esri/hub-common\";\r\n\r\n/**\r\n * For some reason, the webmap resource key names are fancier than other resource keys\r\n * They look like this: r-<webmap-item-id>-<timestamp>\r\n * This interpolation is hard to accomplish given our current setup, so we're just overwriting\r\n * them with \"webmap0\", \"webmap1\" and so forth. This _seems_ to make no difference.\r\n *\r\n * @param model\r\n */\r\nexport function remapWebmapKeys(resources: any = {}): any[] {\r\n let webmapCounter = 0;\r\n return Object.keys(resources).reduce((acc, key) => {\r\n if (getProp(resources, `${key}.type`) === \"webmap\") {\r\n if (key !== `webmap${webmapCounter}`) {\r\n acc.push({\r\n original: key,\r\n updated: `webmap${webmapCounter}`\r\n });\r\n webmapCounter++;\r\n }\r\n }\r\n return 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\nimport { IModel, getProp } from \"@esri/hub-common\";\r\n\r\n/**\r\n * Extract a list of Items this storymap depends on\r\n * At this point we are just extracting webmaps\r\n *\r\n * @param model IModel\r\n */\r\nexport function getStoryMapDependencies(model: IModel): any[] {\r\n const resources = getProp(model, \"data.resources\") || {};\r\n return Object.keys(resources).reduce((acc, key) => {\r\n if (getProp(resources, `${key}.type`) === \"webmap\") {\r\n acc.push(getProp(resources, `${key}.data.itemId`));\r\n }\r\n return 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\nimport { UserSession } from \"@esri/solution-common\";\r\n\r\nexport function getStoryMapSubdomain(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 storymaps on portal?\r\n let result;\r\n if (portalUrl.match(/(qaext|\\.mapsqa)\\.arcgis.com/)) {\r\n result = \"storymapsqa\";\r\n } else if (portalUrl.match(/(devext|\\.mapsdevext)\\.arcgis.com/)) {\r\n result = \"storymapsdev\";\r\n } else if (portalUrl.match(/(www|\\.maps)\\.arcgis.com/)) {\r\n result = \"storymaps\";\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\n/**\r\n * Given a template, process it and interpolate it such that\r\n * we have a model that is ready to be sent to the Portal API\r\n */\r\n\r\nimport { interpolate, IModelTemplate } from \"@esri/hub-common\";\r\nimport { UserSession } from \"@esri/solution-common\";\r\nimport { getPortalEnv } from \"./get-portal-env\";\r\nimport { getStoryMapBaseUrl } from \"./get-storymap-base-url\";\r\nimport { getStoryMapSubdomain } from \"./get-storymap-subdomain\";\r\n\r\nexport function createStoryMapModelFromTemplate(\r\n templateModel: IModelTemplate,\r\n settings: any,\r\n transforms: any,\r\n authentication: UserSession\r\n): Promise<any> {\r\n const timestamp = new Date().getTime();\r\n // Keep these around in case we encounter some old templates\r\n settings.agoenv = getPortalEnv(authentication);\r\n settings.smBase = getStoryMapSubdomain(authentication);\r\n settings.timestamp = new Date().getTime();\r\n // These are used in the oembed resource, as well as the item url\r\n // they have `{{appid}}` in them so that the id of the created item\r\n // will be interpolated into it after the item is created\r\n settings.storyMapBaseUrl = getStoryMapBaseUrl(authentication);\r\n settings.storyMapTemplateUrl = `${settings.storyMapBaseUrl}/stories/{{appid}}`;\r\n settings.storyMapThumnailUrl = `${authentication.portal}/content/items/{{appid}}/info/thumbnail/thumbnail.jpg/?w=400&d=${timestamp}`;\r\n\r\n const model = interpolate(templateModel, settings, transforms);\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\n\r\nexport function getPortalEnv(authentication: UserSession): string {\r\n const portalUrl =\r\n authentication.portal || \"https://www.arcgis.com/sharing/rest\";\r\n let result = \"portal\";\r\n if (portalUrl.match(/(qaext|\\.mapsqa)\\.arcgis.com/)) {\r\n result = \"qaext\";\r\n } else if (portalUrl.match(/(devext|\\.mapsdevext)\\.arcgis.com/)) {\r\n result = \"devext\";\r\n } else if (portalUrl.match(/(www|\\.maps)\\.arcgis.com/)) {\r\n result = \"www\";\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 { getStoryMapSubdomain } from \"./get-storymap-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 getStoryMapBaseUrl(authentication: UserSession): string {\r\n let baseUrl = \"\";\r\n\r\n const subdomain = getStoryMapSubdomain(authentication);\r\n if (subdomain) {\r\n baseUrl = `https://${subdomain}.arcgis.com`;\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/storymaps`;\r\n }\r\n\r\n return baseUrl;\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 Story Map item types.\r\n *\r\n * @module storymap\r\n */\r\n\r\nimport {\r\n IItemTemplate,\r\n IItemProgressCallback,\r\n ICreateItemFromTemplateResponse,\r\n EItemProgressStatus,\r\n UserSession,\r\n generateEmptyCreationResponse\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 { convertStoryMapToTemplate } from \"./helpers/convert-storymap-to-template\";\r\nimport { createStoryMapModelFromTemplate } from \"./helpers/create-storymap-model-from-template\";\r\nimport { createStoryMap } from \"./helpers/create-storymap\";\r\n\r\n/**\r\n * Convert a StoryMap to 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 */\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 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 })\r\n .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 convertStoryMapToTemplate(model);\r\n })\r\n .then(tmpl => {\r\n return tmpl;\r\n });\r\n}\r\n\r\n/**\r\n * Create a StoryMap from the passed in 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 // ensure we have a solution object in the templateDictionary hash\r\n if (!templateDictionary.solution) {\r\n templateDictionary.solution = {};\r\n }\r\n // .title should always be set on the templateDictionary\r\n templateDictionary.solution.title = templateDictionary.title;\r\n\r\n // TODO: Determine if we need any transforms in this new env\r\n const transforms = {};\r\n\r\n // create an object to hold the created site through\r\n // subsequent promise calls\r\n let model: IModel;\r\n\r\n // Create the \"siteModel\" from the template. Does not save the site item yet\r\n // Note: depending on licensing and user privs, will also create the team groups\r\n // and initiative item.\r\n return createStoryMapModelFromTemplate(\r\n template,\r\n templateDictionary,\r\n transforms,\r\n destinationAuthentication\r\n )\r\n .then(interpolated => {\r\n const options = {\r\n assets: interpolated.assets || []\r\n };\r\n return createStoryMap(\r\n interpolated,\r\n templateDictionary.folderId,\r\n options,\r\n destinationAuthentication\r\n );\r\n })\r\n .then(createdModel => {\r\n model = createdModel;\r\n // Update the template dictionary\r\n // TODO: This should be done in whatever receives\r\n // the outcome of this promise chain\r\n templateDictionary[template.itemId] = {\r\n itemId: model.item.id\r\n };\r\n // call the progress callback, which also mutates templateDictionary\r\n const finalStatus = itemProgressCallback(\r\n template.itemId,\r\n EItemProgressStatus.Finished,\r\n template.estimatedDeploymentCostFactor || 2,\r\n model.item.id\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: model.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 ...model\r\n },\r\n id: model.item.id,\r\n type: template.type,\r\n postProcess: false\r\n };\r\n response.item.itemId = model.item.id;\r\n return response;\r\n }\r\n })\r\n .catch(ex => {\r\n itemProgressCallback(template.itemId, EItemProgressStatus.Failed, 0);\r\n throw ex;\r\n });\r\n}\r\n\r\nexport function isAStoryMap(itemType: string): boolean {\r\n let result = false;\r\n if (itemType === \"StoryMap\") {\r\n result = true;\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\n\r\n// TODO ENSURE THIS CREATES IN THE TARGET FOLDER\r\nimport {\r\n IModel,\r\n failSafe,\r\n serializeModel,\r\n interpolateItemId,\r\n stringToBlob\r\n} from \"@esri/hub-common\";\r\n\r\nimport { UserSession } from \"@esri/solution-common\";\r\n\r\nimport {\r\n createItem,\r\n moveItem,\r\n addItemResource,\r\n updateItem,\r\n ICreateItemOptions,\r\n ICreateItemResponse\r\n} from \"@esri/arcgis-rest-portal\";\r\n\r\n/**\r\n * Create a StoryMap from an interpolated template\r\n *\r\n * @param model\r\n * @param options\r\n * @param authentication\r\n */\r\nexport function createStoryMap(\r\n model: IModel,\r\n folderId: string,\r\n options: any,\r\n authentication: UserSession\r\n): Promise<IModel> {\r\n // create an array to hold well-known resources\r\n // that we have to generate from the passed in model\r\n const resources: any[] = [];\r\n\r\n // For unknown 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 createItem(createOptions)\r\n .then((createResponse: ICreateItemResponse) => {\r\n // hold the id in the model\r\n model.item.id = createResponse.id;\r\n // and re-interpolate the item id\r\n model = interpolateItemId(model);\r\n // Compute the item url based on current environment\r\n\r\n // Storymaps store draft data in a timestamped resource attached to the item\r\n // We'll just use the published data for the first \"draft\"\r\n resources.push({\r\n name: model.properties.draftFileName,\r\n file: stringToBlob(JSON.stringify(model.data))\r\n });\r\n resources.push({\r\n name: \"oembed.json\",\r\n file: stringToBlob(JSON.stringify(model.properties.oembed))\r\n });\r\n resources.push({\r\n name: \"oembed.xml\",\r\n file: stringToBlob(model.properties.oembedXML)\r\n });\r\n // remove the properties hash now that we've gotten what we need\r\n delete model.properties;\r\n // update the item with the newly re-interpolated model\r\n return Promise.all([\r\n updateItem({\r\n item: serializeModel(model),\r\n authentication\r\n }),\r\n authentication.getUsername()\r\n ]);\r\n })\r\n .then((responses: any[]) => {\r\n const username = responses[1];\r\n // add the resources\r\n const failSafeAddItemResource = failSafe(addItemResource, {\r\n success: true\r\n });\r\n const resourcePromises = resources.map(resource => {\r\n return failSafeAddItemResource({\r\n id: model.item.id,\r\n owner: username,\r\n resource: resource.file,\r\n name: resource.name,\r\n authentication\r\n });\r\n });\r\n // Fire and forget as these are not critical-path\r\n return Promise.all(resourcePromises);\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","/** @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 Story Map item types.\r\n *\r\n * @module storymap\r\n */\r\n\r\nimport * as common from \"@esri/solution-common\";\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n if (isAStoryMap(itemInfo.type, itemInfo.url)) {\r\n reject(common.fail(\"Classic StoryMap is not yet implemented\"));\r\n } else {\r\n reject(common.fail(itemInfo.id + \" is not a StoryMap\"));\r\n }\r\n });\r\n}\r\n\r\nexport function createItemFromTemplate(\r\n template: common.IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: common.UserSession,\r\n itemProgressCallback: common.IItemProgressCallback\r\n): Promise<common.ICreateItemFromTemplateResponse> {\r\n return new Promise<common.ICreateItemFromTemplateResponse>(resolve => {\r\n if (isAStoryMap(template.type, template.item.url)) {\r\n // Not yet implemented\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Failed,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type));\r\n } else {\r\n // Not valid\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Failed,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type));\r\n }\r\n });\r\n}\r\n\r\nexport function isAStoryMap(itemType: string, itemUrl?: string): boolean {\r\n if (itemUrl) {\r\n return [\r\n /\\/apps\\/Cascade\\//i,\r\n /\\/apps\\/MapJournal\\//i,\r\n /\\/apps\\/MapSeries\\//i,\r\n /\\/apps\\/MapTour\\//i,\r\n /\\/apps\\/Shortlist\\//i,\r\n /\\/apps\\/StoryMap\\//i,\r\n /\\/apps\\/StoryMapBasic\\//i,\r\n /\\/apps\\/StorytellingSwipe\\//i\r\n ].some(pattern => pattern.test(itemUrl));\r\n }\r\n return false;\r\n}\r\n"],"names":["convertStoryMapToTemplate","model","tmpl","createPlaceholderTemplate","item","id","type","key","propifyString","title","createId","clone","cloneObject","data","created","modified","normalizeSolutionTemplateItem","url","resources","webmapCounter","Object","keys","reduce","acc","getProp","push","original","updated","remapWebmapKeys","forEach","remap","nodes","deepStringReplace","typeKeywords","indexOf","unPublishedChangesKW","publishedChangesKW","concat","filter","word","properties","draftFileName","assign","oEmbedTemplates","dependencies","getStoryMapDependencies","Promise","resolve","oembed","version","provider_name","provider_url","width","height","thumbnail_url","thumbnail_height","thumbnail_width","html","cache_age","oembedXML","getStoryMapSubdomain","authentication","portalUrl","portal","result","match","createStoryMapModelFromTemplate","templateModel","settings","transforms","timestamp","Date","getTime","agoenv","getPortalEnv","smBase","storyMapBaseUrl","baseUrl","subdomain","replace","getStoryMapBaseUrl","storyMapTemplateUrl","storyMapThumnailUrl","interpolate","solutionItemId","itemInfo","destAuthentication","srcAuthentication","getItemData","then","template","templateDictionary","destinationAuthentication","itemProgressCallback","itemId","EItemProgressStatus","Started","generateEmptyCreationResponse","solution","interpolated","assets","folderId","options","createOptions","serializeModel","thumbnail","params","createItem","createResponse","interpolateItemId","name","file","stringToBlob","JSON","stringify","all","updateItem","getUsername","responses","username","failSafeAddItemResource","failSafe","addItemResource","success","resourcePromises","map","resource","owner","moveItem","createStoryMap","createdModel","Finished","estimatedDeploymentCostFactor","response","postProcess","removeItem","failSafeRemove","catch","ex","Failed","itemType","isAStoryMap","itemUrl","some","pattern","test","reject","common","fail"],"mappings":";;;;;;;;;;;;;;;;;kxBAsCgBA,EACdC,GAEA,MAAMC,EAAOC,4BAA0BF,EAAMG,KAAKC,GAAIJ,EAAMG,KAAKE,MACjEJ,EAAKK,IAAM,GAAGC,gBAAcP,EAAMG,KAAKK,UAAUC,WAAS,OAE1D,MAAMC,EAAQC,cAAYX,GAC1BC,EAAKW,KAAOF,EAAME,KAGlB,MAAMC,EAAUH,EAAMP,KAAKU,QACrBC,EAAWJ,EAAMP,KAAKW,SAC5Bb,EAAKE,KAAOY,gCAA8BL,EAAMP,MAChDF,EAAKE,KAAKU,QAAUA,EACpBZ,EAAKE,KA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F"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esri/solution-storymap",
3
- "version": "1.3.13",
3
+ "version": "1.3.16",
4
4
  "description": "Manages the creation and deployment of Story Map item types for @esri/solution.js.",
5
5
  "main": "dist/node/index.js",
6
6
  "unpkg": "dist/umd/storymap.umd.min.js",
@@ -17,7 +17,7 @@
17
17
  "@esri/arcgis-rest-portal": "3.4.3",
18
18
  "@esri/arcgis-rest-request": "3.4.3",
19
19
  "@esri/hub-common": "9.29.0",
20
- "rollup": "2.70.2"
20
+ "rollup": "2.66.1"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@esri/arcgis-rest-auth": "3.4.3",
@@ -26,7 +26,7 @@
26
26
  "@esri/hub-common": "9.29.0"
27
27
  },
28
28
  "dependencies": {
29
- "@esri/solution-common": "^1.3.13",
29
+ "@esri/solution-common": "^1.3.16",
30
30
  "tslib": "1.14.1"
31
31
  },
32
32
  "scripts": {
@@ -80,5 +80,5 @@
80
80
  "esri",
81
81
  "ES6"
82
82
  ],
83
- "gitHead": "ee404319048f8e0323933d69c4eb5bbf33c438ec"
83
+ "gitHead": "c87f04e58c80558f19a6d79086b69a965b17db93"
84
84
  }