@esri/solution-simple-types 1.3.16 → 1.4.1
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-simple-types - v1.
|
|
2
|
+
* @esri/solution-simple-types - v1.4.1 - Apache-2.0
|
|
3
3
|
* Copyright (c) 2018-2022 Esri, Inc.
|
|
4
|
-
*
|
|
4
|
+
* Mon Aug 01 2022 14:08:20 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,7 +1,7 @@
|
|
|
1
1
|
/* @preserve
|
|
2
|
-
* @esri/solution-simple-types - v1.
|
|
2
|
+
* @esri/solution-simple-types - v1.4.1 - Apache-2.0
|
|
3
3
|
* Copyright (c) 2018-2022 Esri, Inc.
|
|
4
|
-
*
|
|
4
|
+
* Mon Aug 01 2022 14:08:23 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":"simple-types.umd.min.js","sources":["../../src/dashboard.ts","../../src/webmappingapplication.ts","../../src/helpers/create-item-from-template.ts","../../src/workforce.ts","../../src/helpers/update-notebook-data.ts","../../src/notebook.ts","../../src/oic.ts","../../src/quickcapture.ts","../../src/webmap.ts","../../src/helpers/convert-item-to-template.ts","../../src/simple-types.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 * as common from \"@esri/solution-common\";\r\n\r\n/**\r\n * The relevant elements of a Dashboard widget.\r\n *\r\n * @private\r\n */\r\ninterface IDashboardWidget {\r\n /**\r\n * AGOL item id for some widget types\r\n */\r\n itemId: string;\r\n /**\r\n * Dashboard widget type\r\n */\r\n type: string;\r\n /**\r\n * Dashboard widget datasets if any\r\n * These can be relative references to layers in map a map widget or external datasources\r\n */\r\n datasets?: IDashboardDataset[];\r\n}\r\n\r\n/**\r\n * The relevant elements of a dashboards dataset\r\n *\r\n * @private\r\n */\r\ninterface IDashboardDataset {\r\n /**\r\n * These can be relative references to layers in map a map widget or external datasources\r\n */\r\n dataSource: IDashboardDatasource;\r\n /**\r\n * Dashboard dataset type...we are only concerend with service datasets\r\n */\r\n type: string;\r\n}\r\n\r\n/**\r\n * The relevant datasource properties that describe a dataset\r\n *\r\n * @private\r\n */\r\ninterface IDashboardDatasource {\r\n /**\r\n * When it's an external datasource it will contain the portal itemId\r\n * as well as the individual layerId\r\n */\r\n itemId?: string;\r\n layerId?: any;\r\n /**\r\n * When it's a datasource from a map widget it will contain a reltive path\r\n * DashboardMapId#OperationalLayerId\r\n * For example: b38e032d-bf0c-426f-8036-b86341eb3693#TestLayerForDashBoardMap_632\r\n */\r\n id?: string;\r\n}\r\n\r\n/**\r\n * Converts a dashboard item to a template.\r\n *\r\n * @param itemTemplate Template for the dashboard item\r\n * @returns templatized itemTemplate\r\n */\r\nexport function convertItemToTemplate(\r\n itemTemplate: common.IItemTemplate\r\n): common.IItemTemplate {\r\n return _extractDependencies(itemTemplate);\r\n}\r\n\r\n/**\r\n * Templatizes all itemIds and updates the dependency array\r\n *\r\n * @param itemTemplate Template for the dashboard item\r\n * @returns The updated itemTemplate\r\n * @private\r\n * @private\r\n */\r\nexport function _extractDependencies(\r\n itemTemplate: common.IItemTemplate\r\n): common.IItemTemplate {\r\n // get dependencies from any\r\n const updatePaths: string[] = [\r\n \"data.widgets\",\r\n \"data.headerPanel.selectors\",\r\n \"data.leftPanel.selectors\",\r\n \"data.urlParameters\"\r\n ];\r\n\r\n updatePaths.forEach(path => {\r\n const objs: IDashboardWidget[] = common.getProp(itemTemplate, path);\r\n if (Array.isArray(objs)) {\r\n objs.forEach(obj => {\r\n /* istanbul ignore else */\r\n if (obj.type === \"mapWidget\") {\r\n /* istanbul ignore else */\r\n if (itemTemplate.dependencies.indexOf(obj.itemId) < 0) {\r\n itemTemplate.dependencies.push(obj.itemId);\r\n }\r\n obj.itemId = common.templatizeTerm(obj.itemId, obj.itemId, \".itemId\");\r\n }\r\n /* istanbul ignore else */\r\n if (Array.isArray(obj.datasets)) {\r\n _getDatasourceDependencies(obj, itemTemplate);\r\n }\r\n });\r\n }\r\n });\r\n\r\n return itemTemplate;\r\n}\r\n\r\n/**\r\n * Templatize datasource itemIds and update the dependency array\r\n *\r\n * @param obj A widget, selector, or urlParameter that contains a datasets collection\r\n * @param itemTemplate Template for the dashboard item\r\n * @private\r\n */\r\nexport function _getDatasourceDependencies(\r\n obj: any,\r\n itemTemplate: common.IItemTemplate\r\n): void {\r\n obj.datasets.forEach((dataset: IDashboardDataset) => {\r\n // when the datasource has an itemId is an external datasource\r\n const itemId: string = common.getProp(dataset, \"dataSource.itemId\");\r\n if (itemId) {\r\n if (itemTemplate.dependencies.indexOf(itemId) < 0) {\r\n itemTemplate.dependencies.push(itemId);\r\n }\r\n const layerId: number = common.getProp(dataset, \"dataSource.layerId\");\r\n dataset.dataSource.itemId = common.templatizeTerm(\r\n itemId,\r\n itemId,\r\n layerId !== undefined ? \".layer\" + layerId + \".itemId\" : \".itemId\"\r\n );\r\n /* istanbul ignore else */\r\n if (layerId !== undefined) {\r\n dataset.dataSource.layerId = common.templatizeTerm(\r\n itemId,\r\n itemId,\r\n \".layer\" + layerId + \".layerId\"\r\n );\r\n }\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Templatize field references for datasources and widgets.\r\n *\r\n * @param solutionTemplate The solution item template\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns The solutionTemplate with templatized field references\r\n */\r\nexport function postProcessFieldReferences(\r\n solutionTemplate: common.IItemTemplate,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): common.IItemTemplate {\r\n const updatePaths: string[] = [\r\n \"data.widgets\",\r\n \"data.headerPanel.selectors\",\r\n \"data.leftPanel.selectors\",\r\n \"data.urlParameters\"\r\n ];\r\n\r\n // dashboards reference datasets from other widgets\r\n // add reference IDs to the appropriate datasourceInfos\r\n updatePaths.forEach(path => {\r\n const objs: any = common.getProp(solutionTemplate, path);\r\n _updateDatasourceReferences(objs, datasourceInfos);\r\n });\r\n\r\n // after we know the potential references go ahead and templatize\r\n updatePaths.forEach(path => {\r\n _templatize(solutionTemplate, path, datasourceInfos);\r\n });\r\n\r\n return solutionTemplate;\r\n}\r\n\r\n/**\r\n * Add all dataset ids to the appropriate datasource info object so we can navigate any relative references\r\n *\r\n * @param objs Thes can be widgets, selectors, or urlParameters\r\n * @param datasourceInfos A list of objects that contain key details about the datasources from the application\r\n * @private\r\n */\r\nexport function _updateDatasourceReferences(\r\n objs: any,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n) {\r\n // objects can be events or widgets\r\n /* istanbul ignore else */\r\n if (objs && Array.isArray(objs)) {\r\n objs.forEach(obj => {\r\n if (Array.isArray(obj.datasets)) {\r\n obj.datasets.forEach((dataset: IDashboardDataset) => {\r\n // when the datasource has an itemId it's an external datasource\r\n const itemId: string = common.cleanLayerBasedItemId(\r\n common.getProp(dataset, \"dataSource.itemId\")\r\n );\r\n if (itemId) {\r\n const layerId: number = common.cleanLayerId(\r\n common.getProp(dataset, \"dataSource.layerId\")\r\n );\r\n datasourceInfos.some(ds => {\r\n if (ds.itemId === itemId && ds.layerId === layerId) {\r\n _updateReferences(ds, obj.id);\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n });\r\n } else {\r\n // add placeholder for map layer datasource info so we can know the items that reference them\r\n // needed when item field reference are derived from another widgets datasource eg. <dashboardWidgetId>#datasetname\r\n const id: any = common.getProp(dataset, \"dataSource.id\");\r\n if (id) {\r\n const dashboardLayerId: string = id.split(\"#\")[1];\r\n datasourceInfos.some(ds => {\r\n if (ds.ids.indexOf(dashboardLayerId) > -1) {\r\n _updateReferences(ds, obj.id);\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n });\r\n }\r\n }\r\n });\r\n }\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Templatize all datasets and/or events for the objects at the given path\r\n *\r\n * @param itemTemplate Template for the dashboard item\r\n * @param path A property path to an array of objects that could contain datasets or events\r\n * @param datasourceInfos A list of objects that contain key details about the datasources from the application\r\n * @private\r\n */\r\nexport function _templatize(\r\n itemTemplate: common.IItemTemplate,\r\n path: string,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n) {\r\n const obj: any[] = common.getProp(itemTemplate, path);\r\n /* istanbul ignore else */\r\n if (obj) {\r\n common.setProp(\r\n itemTemplate,\r\n path,\r\n _templatizeByDatasource(obj, datasourceInfos)\r\n );\r\n }\r\n}\r\n\r\n/**\r\n * For any service dataset datasource templatize all field references\r\n *\r\n * @param objs A list of objects that can contain field references\r\n * @param datasourceInfos A list of objects that contain key details about the datasources from the application\r\n * @returns An updated list of objects with templatized field references\r\n * @private\r\n */\r\nexport function _templatizeByDatasource(\r\n objs: any[],\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): any {\r\n if (Array.isArray(objs)) {\r\n return objs.map(obj => {\r\n let _obj: any = obj;\r\n if (Array.isArray(_obj.events)) {\r\n // Events can be associated with datasets but they can also be associated with a target\r\n // In some cases an event will have a source and a target.\r\n // Handle these specifically first to ensure that it has the correct layer reference\r\n _obj.events = _obj.events.map((event: any) => {\r\n const _event: any = event;\r\n /* istanbul ignore else */\r\n if (Array.isArray(_event.actions)) {\r\n _event.actions = _event.actions.map((action: any) => {\r\n const _action: any = action;\r\n if (\r\n _action.fieldMap &&\r\n _action.targetId &&\r\n _action.targetId.indexOf(\"#\") > -1\r\n ) {\r\n const datasourceInfo = _getDatasourceInfo(\r\n _action,\r\n datasourceInfos\r\n );\r\n /* istanbul ignore else */\r\n if (datasourceInfo) {\r\n const fields: any[] = common.getProp(\r\n datasourceInfo,\r\n \"fields\"\r\n );\r\n const basePath: string = common.getProp(\r\n datasourceInfo,\r\n \"basePath\"\r\n );\r\n /* istanbul ignore else */\r\n if (Array.isArray(fields) && basePath) {\r\n _action.fieldMap = _action.fieldMap.map((m: any) => {\r\n const _m: any = m;\r\n _m.targetName = common.templatizeFieldReferences(\r\n _m.targetName,\r\n fields,\r\n basePath\r\n );\r\n return _m;\r\n });\r\n }\r\n }\r\n }\r\n return _action;\r\n });\r\n }\r\n return _event;\r\n });\r\n }\r\n if (Array.isArray(_obj.datasets)) {\r\n _obj.datasets = _obj.datasets.map((dataset: any) => {\r\n let _dataset: any = dataset;\r\n if (_dataset.type === \"serviceDataset\") {\r\n const datasourceInfo = _getDatasourceInfo(dataset, datasourceInfos);\r\n /* istanbul ignore else */\r\n if (datasourceInfo) {\r\n const fields: any[] = common.getProp(datasourceInfo, \"fields\");\r\n const basePath: string = common.getProp(\r\n datasourceInfo,\r\n \"basePath\"\r\n );\r\n /* istanbul ignore else */\r\n if (Array.isArray(fields) && basePath) {\r\n _obj = common.templatizeFieldReferences(_obj, fields, basePath);\r\n _dataset = common.templatizeFieldReferences(\r\n _dataset,\r\n fields,\r\n basePath\r\n );\r\n }\r\n }\r\n }\r\n return _dataset;\r\n });\r\n return _obj;\r\n } else return _obj;\r\n });\r\n } else {\r\n return objs;\r\n }\r\n}\r\n\r\n/**\r\n * Find the appropriate datasource info object from the datasourceInfo collection\r\n *\r\n * @param obj Can be a Dataset or an event\r\n * @param datasourceInfos A list of objects that contain key details about the datasources from the application\r\n * @returns The supporting datasource info for the given object\r\n * @private\r\n */\r\nexport function _getDatasourceInfo(\r\n obj: any,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): any {\r\n let info: any;\r\n // the datasource will have an id property when it's referencing a map layer\r\n // the fields collection will already be defined\r\n const id: string =\r\n common.getProp(obj, \"dataSource.id\") || common.getProp(obj, \"targetId\");\r\n if (id) {\r\n const dashboardLayerId: string = id.split(\"#\")[1];\r\n if (\r\n !datasourceInfos.some(di => {\r\n info = di.ids.indexOf(dashboardLayerId) > -1 ? di : info;\r\n return di.ids.indexOf(dashboardLayerId) > -1;\r\n })\r\n ) {\r\n // in some cases the id will not contain a layer name...it will have the dashboard id for another widget\r\n // in that case lookup the datasource from referenced widget\r\n const dashboardWidgetId: string = id.split(\"#\")[0];\r\n datasourceInfos.some(di => {\r\n const references: string[] = di.references || [];\r\n const hasRef: boolean = references.indexOf(dashboardWidgetId) > -1;\r\n info = hasRef ? di : info;\r\n return hasRef;\r\n });\r\n }\r\n } else {\r\n // otherwise match the itemId and the layerId to get the correct fields and path\r\n const itemId: any = common.cleanLayerBasedItemId(\r\n common.getProp(obj, \"dataSource.itemId\")\r\n );\r\n const layerId: any = common.cleanLayerId(\r\n common.getProp(obj, \"dataSource.layerId\")\r\n );\r\n /* istanbul ignore else */\r\n if (itemId) {\r\n datasourceInfos.some(di => {\r\n const matches: boolean = itemId === di.itemId && layerId === di.layerId;\r\n info = matches ? di : info;\r\n return matches;\r\n });\r\n }\r\n }\r\n return info;\r\n}\r\n\r\n/**\r\n * Verifies if the datasource info contains the given id and adds it if not\r\n *\r\n * @param ds The datasource info to add the reference to\r\n * @param id The id from dashboard object, commonly another widget\r\n * @private\r\n */\r\nexport function _updateReferences(\r\n ds: common.IDatasourceInfo,\r\n id: string\r\n): void {\r\n ds.references = Array.isArray(ds.references) ? ds.references : [];\r\n if (ds.references.indexOf(id) < 0) {\r\n ds.references.push(id);\r\n }\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\nimport * as common from \"@esri/solution-common\";\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\n/**\r\n * Converts a web mapping application item into a template.\r\n *\r\n * @param itemInfo Info about the item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @returns A promise that will resolve when the template has been created\r\n */\r\nexport function convertItemToTemplate(\r\n itemTemplate: common.IItemTemplate,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n // Remove org base URL and app id, e.g.,\r\n // http://anOrg.maps.arcgis.com/apps/CrowdsourcePolling/index.html?appid=6fc5992522d34a6b5ce80d17835eea21\r\n // to\r\n // <placeholder(SERVER_NAME)>/apps/CrowdsourcePolling/index.html?appid={{<itemId>.id}}\r\n // Need to add placeholder server name because otherwise AGOL makes URL null\r\n let portalUrl: string = \"\";\r\n if (itemTemplate.item.url) {\r\n const templatizedUrl = itemTemplate.item.url;\r\n const iSep = templatizedUrl.indexOf(\"//\");\r\n itemTemplate.item.url =\r\n common.placeholder(common.SERVER_NAME) + // add placeholder server name\r\n templatizedUrl.substring(\r\n templatizedUrl.indexOf(\"/\", iSep + 2),\r\n templatizedUrl.lastIndexOf(\"=\") + 1\r\n ) +\r\n itemTemplate.item.id; // templatized id\r\n\r\n portalUrl = templatizedUrl.replace(\r\n templatizedUrl.substring(templatizedUrl.indexOf(\"/\", iSep + 2)),\r\n \"\"\r\n );\r\n }\r\n\r\n // Extract dependencies\r\n itemTemplate.dependencies = _extractDependencies(itemTemplate);\r\n\r\n // Set the folder\r\n common.setProp(itemTemplate, \"data.folderId\", \"{{folderId}}\");\r\n // Set the map or group after we've extracted them as dependencies\r\n _templatizeIdPaths(itemTemplate, [\r\n \"data.map.itemId\",\r\n \"data.map.appProxy.mapItemId\",\r\n \"data.values.webmap\",\r\n \"data.values.group\"\r\n ]);\r\n\r\n // force the appItemId to be pulled directly from the template item\r\n // this is to address solution.js #124\r\n _templatizeIdPath(itemTemplate, \"data.appItemId\", itemTemplate.itemId);\r\n\r\n setValues(\r\n itemTemplate,\r\n [\r\n \"data.logo\",\r\n \"data.map.portalUrl\",\r\n \"data.portalUrl\",\r\n \"data.httpProxy.url\"\r\n ],\r\n common.placeholder(common.SERVER_NAME)\r\n );\r\n\r\n common.setProp(\r\n itemTemplate,\r\n \"data.geometryService\",\r\n common.placeholder(common.GEOMETRY_SERVER_NAME)\r\n );\r\n\r\n templatizeDatasources(itemTemplate, srcAuthentication, portalUrl).then(\r\n () => {\r\n templatizeWidgets(\r\n itemTemplate,\r\n srcAuthentication,\r\n portalUrl,\r\n \"data.widgetPool.widgets\"\r\n ).then(\r\n _itemTemplate => {\r\n templatizeWidgets(\r\n _itemTemplate,\r\n srcAuthentication,\r\n portalUrl,\r\n \"data.widgetOnScreen.widgets\",\r\n true\r\n ).then(\r\n updatedItemTemplate => {\r\n templatizeValues(\r\n updatedItemTemplate,\r\n srcAuthentication,\r\n portalUrl,\r\n \"data.values\"\r\n ).then(\r\n _updatedItemTemplate => {\r\n resolve(_updatedItemTemplate);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n });\r\n}\r\n\r\nexport function templatizeDatasources(\r\n itemTemplate: common.IItemTemplate,\r\n authentication: common.UserSession,\r\n portalUrl: string\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n const dataSources: any = common.getProp(\r\n itemTemplate,\r\n \"data.dataSource.dataSources\"\r\n );\r\n if (dataSources && Object.keys(dataSources).length > 0) {\r\n const pendingRequests = new Array<Promise<void>>();\r\n Object.keys(dataSources).forEach(k => {\r\n const ds: any = dataSources[k];\r\n common.setProp(ds, \"portalUrl\", common.placeholder(common.SERVER_NAME));\r\n const itemId: any = common.getProp(ds, \"itemId\");\r\n if (common.getProp(ds, \"url\")) {\r\n if (itemId) {\r\n const layerId = ds.url.substr(\r\n (ds.url as string).lastIndexOf(\"/\") + 1\r\n );\r\n ds.itemId = common.templatizeTerm(\r\n itemId,\r\n itemId,\r\n \".layer\" + layerId + \".itemId\"\r\n );\r\n }\r\n const urlResults: any = findUrls(\r\n ds.url,\r\n portalUrl,\r\n [],\r\n [],\r\n authentication\r\n );\r\n pendingRequests.push(\r\n new Promise<void>((resolveReq, rejectReq) => {\r\n handleServiceRequests(\r\n urlResults.serviceRequests,\r\n urlResults.requestUrls,\r\n urlResults.testString\r\n ).then(\r\n response => {\r\n ds.url = response;\r\n resolveReq();\r\n },\r\n e => rejectReq(common.fail(e))\r\n );\r\n })\r\n );\r\n } else {\r\n if (itemId) {\r\n ds.itemId = common.templatizeTerm(itemId, itemId, \".itemId\");\r\n }\r\n }\r\n });\r\n Promise.all(pendingRequests).then(\r\n () => resolve(itemTemplate),\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve(itemTemplate);\r\n }\r\n });\r\n}\r\n\r\nexport function templatizeWidgets(\r\n itemTemplate: common.IItemTemplate,\r\n authentication: common.UserSession,\r\n portalUrl: string,\r\n widgetPath: string,\r\n isOnScreen = false\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n // update widgets\r\n const widgets: any[] = common.getProp(itemTemplate, widgetPath) || [];\r\n let serviceRequests: any[] = [];\r\n let requestUrls: string[] = [];\r\n\r\n widgets.forEach(widget => {\r\n /* istanbul ignore else */\r\n if (!isOnScreen && common.getProp(widget, \"icon\")) {\r\n setValues(widget, [\"icon\"], common.placeholder(common.SERVER_NAME));\r\n }\r\n const config: any = widget.config;\r\n if (config) {\r\n const sConfig: string = JSON.stringify(config);\r\n const urlResults: any = findUrls(\r\n sConfig,\r\n portalUrl,\r\n requestUrls,\r\n serviceRequests,\r\n authentication\r\n );\r\n\r\n widget.config = JSON.parse(urlResults.testString);\r\n serviceRequests = urlResults.serviceRequests;\r\n requestUrls = urlResults.requestUrls;\r\n }\r\n });\r\n\r\n if (serviceRequests.length > 0) {\r\n const sWidgets: string = JSON.stringify(widgets);\r\n handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(\r\n response => {\r\n common.setProp(itemTemplate, widgetPath, JSON.parse(response));\r\n resolve(itemTemplate);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve(itemTemplate);\r\n }\r\n });\r\n}\r\n\r\nexport function templatizeValues(\r\n itemTemplate: common.IItemTemplate,\r\n authentication: common.UserSession,\r\n portalUrl: string,\r\n widgetPath: string\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n // update properties of values collection for web app templates\r\n let values: any = common.getProp(itemTemplate, widgetPath);\r\n let serviceRequests: any[] = [];\r\n let requestUrls: string[] = [];\r\n\r\n if (values) {\r\n if (common.getProp(values, \"icon\")) {\r\n setValues(values, [\"icon\"], common.placeholder(common.SERVER_NAME));\r\n }\r\n\r\n const sConfig: string = JSON.stringify(values);\r\n const urlResults: any = findUrls(\r\n sConfig,\r\n portalUrl,\r\n requestUrls,\r\n serviceRequests,\r\n authentication\r\n );\r\n\r\n values = JSON.parse(urlResults.testString);\r\n serviceRequests = urlResults.serviceRequests;\r\n requestUrls = urlResults.requestUrls;\r\n }\r\n\r\n if (serviceRequests.length > 0) {\r\n const sWidgets: string = JSON.stringify(values);\r\n handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(\r\n response => {\r\n common.setProp(itemTemplate, widgetPath, JSON.parse(response));\r\n resolve(itemTemplate);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve(itemTemplate);\r\n }\r\n });\r\n}\r\n\r\nexport function handleServiceRequests(\r\n serviceRequests: any[],\r\n requestUrls: string[],\r\n objString: string\r\n): Promise<string> {\r\n return new Promise<string>((resolve, reject) => {\r\n if (serviceRequests && serviceRequests.length > 0) {\r\n let i: number = 0;\r\n Promise.all(serviceRequests).then(\r\n serviceResponses => {\r\n serviceResponses.forEach(serviceResponse => {\r\n if (common.getProp(serviceResponse, \"serviceItemId\")) {\r\n const serviceTemplate: string =\r\n \"{{\" +\r\n serviceResponse.serviceItemId +\r\n (serviceResponse.hasOwnProperty(\"id\")\r\n ? \".layer\" + serviceResponse.id\r\n : \"\") +\r\n \".url}}\";\r\n objString = replaceUrl(\r\n objString,\r\n requestUrls[i],\r\n serviceTemplate,\r\n true\r\n );\r\n }\r\n i++;\r\n });\r\n resolve(objString);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve(objString);\r\n }\r\n });\r\n}\r\n\r\nexport function findUrls(\r\n testString: string,\r\n portalUrl: string,\r\n requestUrls: string[],\r\n serviceRequests: any[],\r\n authentication: common.UserSession\r\n) {\r\n const options: any = {\r\n f: \"json\",\r\n authentication: authentication\r\n };\r\n // test for URLs\r\n const results = testString.match(/(\\bhttps?:\\/\\/[-A-Z0-9/._]*)/gim);\r\n if (results && results.length) {\r\n results.forEach((url: string) => {\r\n if (url.indexOf(\"NAServer\") > -1) {\r\n testString = replaceUrl(\r\n testString,\r\n url,\r\n common.placeholder(common.NA_SERVER_NAME)\r\n );\r\n } else if (url.indexOf(\"GeocodeServer\") > -1) {\r\n testString = replaceUrl(\r\n testString,\r\n url,\r\n common.placeholder(common.GEOCODE_SERVER_NAME)\r\n );\r\n } else if (portalUrl && url.indexOf(portalUrl) > -1) {\r\n testString = replaceUrl(\r\n testString,\r\n portalUrl,\r\n common.placeholder(common.SERVER_NAME)\r\n );\r\n } else if (url.indexOf(\"FeatureServer\") > -1) {\r\n if (requestUrls.indexOf(url) === -1) {\r\n requestUrls.push(url);\r\n serviceRequests.push(common.rest_request(url, options));\r\n }\r\n }\r\n });\r\n }\r\n return {\r\n testString,\r\n requestUrls,\r\n serviceRequests\r\n };\r\n}\r\n\r\n/**\r\n * Replace url with templatized url value\r\n *\r\n * @param obj can be a single url string or a stringified JSON object\r\n * @param url the current url we are testing for\r\n * @param newUrl the templatized url\r\n * @param validateFullUrl should only replace url when we have a full match.\r\n * This property is only relevant when the obj is a stringified JSON object.\r\n *\r\n * @returns the obj with any instances of the url replaced\r\n */\r\nexport function replaceUrl(\r\n obj: string,\r\n url: string,\r\n newUrl: string,\r\n validateFullUrl: boolean = false\r\n) {\r\n const enforceFullUrl: boolean = validateFullUrl && obj.indexOf('\"') > -1;\r\n const re = new RegExp(enforceFullUrl ? '\"' + url + '\"' : url, \"gmi\");\r\n return obj.replace(re, enforceFullUrl ? '\"' + newUrl + '\"' : newUrl);\r\n}\r\n\r\nexport function setValues(\r\n itemTemplate: common.IItemTemplate,\r\n paths: string[],\r\n base: string\r\n) {\r\n paths.forEach(path => {\r\n const url: string = common.getProp(itemTemplate, path);\r\n if (url) {\r\n const subString: string = url.substring(\r\n url.indexOf(\"/\", url.indexOf(\"//\") + 2)\r\n );\r\n common.setProp(\r\n itemTemplate,\r\n path,\r\n subString !== url ? base + subString : base\r\n );\r\n }\r\n });\r\n}\r\n\r\nexport function fineTuneCreatedItem(\r\n originalTemplate: common.IItemTemplate,\r\n newlyCreatedItem: common.IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: common.UserSession\r\n): Promise<void> {\r\n return new Promise<void>(resolve => {\r\n // If this is a Web AppBuilder application, we will create a Code Attachment for downloading\r\n if (\r\n common.hasAnyKeyword(originalTemplate, [\r\n \"WAB2D\",\r\n \"WAB3D\",\r\n \"Web AppBuilder\"\r\n ])\r\n ) {\r\n // Update item so properties like appItemId can now be set now that we know the new apps ID\r\n const updateOptions: common.IItemUpdate = {\r\n id: newlyCreatedItem.itemId,\r\n url: newlyCreatedItem.item.url,\r\n data: newlyCreatedItem.data\r\n };\r\n const updateDef = common.updateItem(\r\n updateOptions,\r\n destinationAuthentication\r\n );\r\n\r\n const itemInfo = {\r\n tags: originalTemplate.item.tags,\r\n title: originalTemplate.item.title,\r\n type: \"Code Attachment\",\r\n typeKeywords: [\"Code\", \"Javascript\", \"Web Mapping Application\"],\r\n relationshipType: \"WMA2Code\",\r\n originItemId: newlyCreatedItem.itemId,\r\n url:\r\n common.checkUrlPathTermination(\r\n common.replaceInTemplate(\r\n common.placeholder(common.SERVER_NAME),\r\n templateDictionary\r\n )\r\n ) +\r\n \"sharing/rest/content/items/\" +\r\n newlyCreatedItem.itemId +\r\n \"/package\"\r\n };\r\n\r\n const createItemWithDataDef = common.createItemWithData(\r\n itemInfo,\r\n {},\r\n destinationAuthentication,\r\n templateDictionary.folderId\r\n );\r\n\r\n Promise.all([updateDef, createItemWithDataDef]).then(\r\n () => resolve(null),\r\n () => resolve(null)\r\n );\r\n } else {\r\n // Otherwise, nothing extra needed\r\n resolve(null);\r\n }\r\n });\r\n}\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\n/**\r\n * Gets the ids of the dependencies of an AGOL webapp item.\r\n *\r\n * @param fullItem A webapp item whose dependencies are sought\r\n * @returns A promise that will resolve with list of dependent ids\r\n * @private\r\n */\r\nexport function _extractDependencies(model: any): string[] {\r\n let processor = _getGenericWebAppDependencies;\r\n\r\n /*\r\n if (common.hasTypeKeyword(model, \"Story Map\")) {\r\n processor = getStoryMapDependencies;\r\n }\r\n */\r\n\r\n if (common.hasAnyKeyword(model, [\"WAB2D\", \"WAB3D\", \"Web AppBuilder\"])) {\r\n processor = _getWABDependencies;\r\n }\r\n\r\n return processor(model);\r\n}\r\n\r\n/**\r\n * Generic Web App Dependencies\r\n *\r\n * @private\r\n */\r\nexport function _getGenericWebAppDependencies(model: any): any {\r\n const props = [\"data.values.webmap\", \"data.values.group\"];\r\n return common.getProps(model, props);\r\n}\r\n\r\n//???\r\nexport function _getWABDependencies(model: any): string[] {\r\n const deps = [] as string[];\r\n const v = common.getProp(model, \"data.map.itemId\");\r\n if (v) {\r\n deps.push(v);\r\n }\r\n const dataSources = common.getProp(model, \"data.dataSource.dataSources\");\r\n if (dataSources) {\r\n Object.keys(dataSources).forEach(k => {\r\n const ds: any = dataSources[k];\r\n if (ds.itemId) {\r\n deps.push(ds.itemId);\r\n }\r\n });\r\n }\r\n return deps;\r\n}\r\n\r\n/**\r\n * Templatizes id properties for the paths provided\r\n *\r\n * @param itemTemplate The solution item template\r\n * @param paths A list of property paths that contain ids\r\n * @private\r\n */\r\nexport function _templatizeIdPaths(\r\n itemTemplate: common.IItemTemplate,\r\n paths: string[]\r\n) {\r\n paths.forEach(path => {\r\n const id: any = common.getProp(itemTemplate, path);\r\n _templatizeIdPath(itemTemplate, path, id);\r\n });\r\n}\r\n\r\n/**\r\n * Templatizes id property for the path provided\r\n *\r\n * @param itemTemplate The solution item template\r\n * @param path A path to an id property\r\n * @param id The base id to use when templatizing\r\n * @private\r\n */\r\nexport function _templatizeIdPath(\r\n itemTemplate: common.IItemTemplate,\r\n path: string,\r\n id: string\r\n) {\r\n common.setProp(itemTemplate, path, common.templatizeTerm(id, id, \".itemId\"));\r\n}\r\n\r\n/**\r\n * Templatize field references for datasources and widgets.\r\n *\r\n * @param solutionTemplate The solution item template\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns The solutionTemplate with templatized field references\r\n */\r\nexport function postProcessFieldReferences(\r\n solutionTemplate: common.IItemTemplate,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): common.IItemTemplate {\r\n // handle datasources common for WAB apps\r\n const dataSources: any = common.getProp(\r\n solutionTemplate,\r\n \"data.dataSource.dataSources\"\r\n );\r\n if (dataSources && Object.keys(dataSources).length > 0) {\r\n Object.keys(dataSources).forEach(k => {\r\n const ds: any = dataSources[k];\r\n dataSources[k] = _templatizeObject(ds, datasourceInfos);\r\n });\r\n common.setProp(\r\n solutionTemplate,\r\n \"data.dataSource.dataSources\",\r\n dataSources\r\n );\r\n }\r\n\r\n // handle widgets common for WAB apps\r\n const paths: string[] = [\r\n \"data.widgetPool.widgets\",\r\n \"data.widgetOnScreen.widgets\"\r\n ];\r\n paths.forEach(path => {\r\n const widgets = common.getProp(solutionTemplate, path);\r\n if (widgets) {\r\n common.setProp(\r\n solutionTemplate,\r\n path,\r\n _templatizeObjectArray(widgets, datasourceInfos)\r\n );\r\n }\r\n });\r\n\r\n // handle values common for web app templates\r\n const values: any = common.getProp(solutionTemplate, \"data.values\");\r\n if (values) {\r\n common.setProp(\r\n solutionTemplate,\r\n \"data.values\",\r\n _templatizeObject(values, datasourceInfos)\r\n );\r\n }\r\n\r\n return solutionTemplate;\r\n}\r\n\r\n/**\r\n * Templatize field references for given dataSource from the web application.\r\n *\r\n * @param obj The dataSource or widget object from the web application.\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns The dataSource with templatized field references\r\n * @private\r\n */\r\nexport function _templatizeObject(\r\n obj: any,\r\n datasourceInfos: common.IDatasourceInfo[],\r\n templatizeKeys: boolean = false\r\n): any {\r\n obj = _prioritizedTests(obj, datasourceInfos, templatizeKeys);\r\n const replaceOrder: common.IDatasourceInfo[] = _getReplaceOrder(\r\n obj,\r\n datasourceInfos\r\n );\r\n replaceOrder.forEach(ds => {\r\n obj = common.templatizeFieldReferences(\r\n obj,\r\n ds.fields,\r\n ds.basePath,\r\n templatizeKeys\r\n );\r\n });\r\n return obj;\r\n}\r\n\r\n/**\r\n * Templatize field references from an array of various objects from the web application.\r\n *\r\n * @param objects A list of widgets or objects from the web application that may contain field references.\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns The widgets with templatized field references\r\n * @private\r\n */\r\nexport function _templatizeObjectArray(\r\n objects: any[],\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): any {\r\n const updateKeyObjects: string[] = [\"SmartEditor\", \"Screening\"];\r\n return objects.map(obj => {\r\n // only templatize the config and lower\r\n if (obj.config) {\r\n const templatizeKeys: boolean = updateKeyObjects.indexOf(obj.name) > -1;\r\n obj.config = _templatizeObject(\r\n obj.config,\r\n datasourceInfos,\r\n templatizeKeys\r\n );\r\n }\r\n return obj;\r\n });\r\n}\r\n\r\n/**\r\n * Gets an order for testing wit the various datasource info objects against the widget or dataSource.\r\n * A widget or dataSource that contain a layers url or webmap layer id are more likely\r\n * to have field references from that layer.\r\n *\r\n * @param obj The dataSource or widget object from the web application.\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns A list of datasourceInfo objects sorted based on the presence of a layers url or id\r\n * @private\r\n */\r\nexport function _getReplaceOrder(\r\n obj: any,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n) {\r\n const objString: string = JSON.stringify(obj);\r\n\r\n // If we don't find any layer url, web map layer id, service url, agol itemId then remove the datasource.\r\n const _datasourceInfos: common.IDatasourceInfo[] = datasourceInfos.filter(\r\n ds => _getSortOrder(ds, objString) < 4\r\n );\r\n return _datasourceInfos.sort((a, b) => {\r\n return _getSortOrder(a, objString) - _getSortOrder(b, objString);\r\n });\r\n}\r\n\r\n/**\r\n * Determine an order for checking field names against a dataSource or widget.\r\n * Sort order preference is set in this order: layer url, web map layer id, service url, agol itemId\r\n *\r\n * @param datasourceInfo The datasource object with key properties about the service.\r\n * @param testString A stringified version of a widget or dataSource\r\n * @returns The prioritized order for testing\r\n * @private\r\n */\r\nexport function _getSortOrder(\r\n datasourceInfo: common.IDatasourceInfo,\r\n testString: string\r\n): number {\r\n const url = datasourceInfo.url;\r\n const itemId = datasourceInfo.itemId;\r\n const layerId = datasourceInfo.layerId;\r\n\r\n // if we have the url and the layerID and its found prioritize it first\r\n // else if we find the maps layer id prioritze it first\r\n let layerUrlTest: any;\r\n if (url && !isNaN(layerId)) {\r\n layerUrlTest = new RegExp(\r\n url.replace(/[.]/, \".layer\" + layerId + \".\"),\r\n \"gm\"\r\n );\r\n }\r\n if (layerUrlTest && layerUrlTest.test(testString)) {\r\n return 1;\r\n } else if (datasourceInfo.ids.length > 0) {\r\n if (\r\n datasourceInfo.ids.some(id => {\r\n const layerMapIdTest: any = new RegExp(id, \"gm\");\r\n return layerMapIdTest.test(testString);\r\n })\r\n ) {\r\n return 1;\r\n }\r\n }\r\n\r\n // if neither full layer url or map layer id are found...check to see if we can\r\n // find the base service url\r\n if (url) {\r\n const serviceUrlTest: any = new RegExp(url, \"gm\");\r\n if (serviceUrlTest.test(testString)) {\r\n return 2;\r\n }\r\n }\r\n // if none of the above see if we can find an AGOL item id reference\r\n if (itemId) {\r\n const itemIdTest: any = new RegExp(itemId, \"gm\");\r\n if (itemIdTest.test(testString)) {\r\n return 3;\r\n }\r\n }\r\n return 4;\r\n}\r\n\r\n/**\r\n * These tests will run prior to the tests associated with the higher level tests based on sort order.\r\n * The tests work more like cloning an object where we go through and review each individual property.\r\n * If we find a url or webmap layer id we will templatize the parent object that contains this property.\r\n * Many widgets will store one of these two properties in an object that will also contain various field references.\r\n *\r\n * @param obj The dataSource or widget object from the application\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns An updated instance of the dataSource or widget with as many field references templatized as possible.\r\n * @private\r\n */\r\nexport function _prioritizedTests(\r\n obj: any,\r\n datasourceInfos: common.IDatasourceInfo[],\r\n templatizeKeys: boolean\r\n): any {\r\n const objString: string = JSON.stringify(obj);\r\n const hasDatasources = datasourceInfos.filter(ds => {\r\n let urlTest: any;\r\n if (ds.url && !isNaN(ds.layerId)) {\r\n urlTest = new RegExp(\r\n ds.url.replace(/[.]/, \".layer\" + ds.layerId + \".\"),\r\n \"gm\"\r\n );\r\n }\r\n\r\n let hasMapLayerId: boolean = false;\r\n if (ds.ids.length > 0) {\r\n hasMapLayerId = ds.ids.some(id => {\r\n const idTest: any = new RegExp(id, \"gm\");\r\n return idTest.test(objString);\r\n });\r\n }\r\n\r\n if (hasMapLayerId || (urlTest && urlTest.test(objString))) {\r\n return ds;\r\n }\r\n });\r\n if (hasDatasources.length > 0) {\r\n hasDatasources.forEach(ds => {\r\n // specific url reference is the most common\r\n obj = _templatizeParentByURL(obj, ds, templatizeKeys);\r\n if (ds.ids.length > 0) {\r\n // the second most common is to use the layerId from the webmap\r\n ds.ids.forEach(id => {\r\n obj = _templatizeParentByWebMapLayerId(obj, ds, id, templatizeKeys);\r\n });\r\n }\r\n });\r\n }\r\n return obj;\r\n}\r\n\r\n/**\r\n * This is very close to common.cloneObject but will test if an object\r\n * has one of the datasource urls as a property. If it finds one it will\r\n * templatize it's parent based on the fields from that datasource\r\n *\r\n * @param obj The dataSource or widget object from the application\r\n * @param ds A datasourceInfo object to use for testing against the current dataSource or widget\r\n * @returns The updated instance of the object with as many field references templatized as possible\r\n * @private\r\n */\r\nexport function _templatizeParentByURL(\r\n obj: { [index: string]: any },\r\n ds: common.IDatasourceInfo,\r\n templatizeKeys: boolean\r\n): any {\r\n let clone: { [index: string]: any } = {};\r\n const url = ds.url;\r\n const layerId = ds.layerId;\r\n\r\n let urlTest: any;\r\n if (url && !isNaN(layerId)) {\r\n urlTest = new RegExp(url.replace(/[.]/, \".layer\" + layerId + \".\"), \"gm\");\r\n }\r\n\r\n if (Array.isArray(obj)) {\r\n clone = obj.map(c => {\r\n return _templatizeParentByURL(c, ds, templatizeKeys);\r\n });\r\n } else if (typeof obj === \"object\") {\r\n for (const i in obj) {\r\n if (obj[i] != null && typeof obj[i] === \"object\") {\r\n clone[i] = _templatizeParentByURL(obj[i], ds, templatizeKeys);\r\n } else {\r\n if (urlTest && urlTest.test(obj[i])) {\r\n obj = common.templatizeFieldReferences(\r\n obj,\r\n ds.fields,\r\n ds.basePath,\r\n templatizeKeys\r\n );\r\n }\r\n clone[i] = obj[i];\r\n }\r\n }\r\n } else {\r\n clone = obj;\r\n }\r\n return clone;\r\n}\r\n\r\n/**\r\n * This is very close to common.cloneObject but will test if an object\r\n * has one of the datasource webmap layer ids as a property. If it finds one it will\r\n * templatize it's parent based on the fields from that datasource.\r\n *\r\n * @param obj The dataSource or widget object from the application\r\n * @param ds A datasourceInfo object to use for testing against the current dataSource or widget\r\n * @param id A webmap layer id to test with.\r\n * @returns The updated instance of the object with as many field references templatized as possible\r\n * @private\r\n */\r\nexport function _templatizeParentByWebMapLayerId(\r\n obj: { [index: string]: any },\r\n ds: common.IDatasourceInfo,\r\n id: string,\r\n templatizeKeys: boolean\r\n): any {\r\n let clone: { [index: string]: any } = {};\r\n const idTest: any = new RegExp(id, \"gm\");\r\n if (Array.isArray(obj)) {\r\n clone = obj.map(c => {\r\n return _templatizeParentByWebMapLayerId(c, ds, id, templatizeKeys);\r\n });\r\n } else if (typeof obj === \"object\") {\r\n for (const i in obj) {\r\n if (obj[i] !== null) {\r\n // In some web application templates they store a stringified version of an object that can\r\n // contain multiple layer references at a very high level on the main values collection.\r\n // This was causing many other more typical layer references to be set incorrectly as the first\r\n // layerId found in this high level string would be used against the main object.\r\n let parsedProp: any;\r\n try {\r\n parsedProp = JSON.parse(obj[i]);\r\n } catch (error) {\r\n parsedProp = undefined;\r\n }\r\n if (parsedProp && typeof parsedProp === \"object\") {\r\n clone[i] = JSON.stringify(\r\n _templatizeParentByWebMapLayerId(parsedProp, ds, id, templatizeKeys)\r\n );\r\n } else if (typeof obj[i] === \"object\") {\r\n // some widgets store the layerId as a key to a collection of details that contain field references\r\n if (idTest.test(i) && templatizeKeys) {\r\n obj[i] = common.templatizeFieldReferences(\r\n obj[i],\r\n ds.fields,\r\n ds.basePath,\r\n templatizeKeys\r\n );\r\n }\r\n clone[i] = _templatizeParentByWebMapLayerId(\r\n obj[i],\r\n ds,\r\n id,\r\n templatizeKeys\r\n );\r\n } else {\r\n if (idTest.test(obj[i])) {\r\n obj = common.templatizeFieldReferences(\r\n obj,\r\n ds.fields,\r\n ds.basePath,\r\n templatizeKeys\r\n );\r\n }\r\n clone[i] = obj[i];\r\n }\r\n } else {\r\n clone[i] = obj[i];\r\n }\r\n }\r\n } else {\r\n clone = obj;\r\n }\r\n return clone;\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 * as common from \"@esri/solution-common\";\r\nimport * as notebook from \"../notebook\";\r\nimport * as webmappingapplication from \"../webmappingapplication\";\r\nimport * as workforce from \"../workforce\";\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 // Interrupt process if progress callback returns `false`\r\n if (\r\n !itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Started,\r\n 0\r\n )\r\n ) {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Ignored,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type));\r\n } else {\r\n // Replace the templatized symbols in a copy of the template\r\n let newItemTemplate: common.IItemTemplate = common.cloneObject(template);\r\n newItemTemplate = common.replaceInTemplate(\r\n newItemTemplate,\r\n templateDictionary\r\n );\r\n\r\n // Create the item, then update its URL with its new id\r\n\r\n // some fieldnames are used as keys for objects\r\n // when we templatize field references for web applications we first stringify the components of the\r\n // web application that could contain field references and then serach for them with a regular expression.\r\n // We also need to stringify the web application when de-templatizing so it will find all of these occurrences as well.\r\n if (template.type === \"Web Mapping Application\" && template.data) {\r\n newItemTemplate = JSON.parse(\r\n common.replaceInTemplate(\r\n JSON.stringify(newItemTemplate),\r\n templateDictionary\r\n )\r\n );\r\n }\r\n\r\n if (template.item.thumbnail) {\r\n newItemTemplate.item.thumbnail = template.item.thumbnail; // make sure that our File is still there\r\n }\r\n\r\n common\r\n .createItemWithData(\r\n newItemTemplate.item,\r\n newItemTemplate.data,\r\n destinationAuthentication,\r\n templateDictionary.folderId\r\n )\r\n .then(\r\n createResponse => {\r\n // Interrupt process if progress callback returns `false`\r\n if (\r\n !itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Created,\r\n template.estimatedDeploymentCostFactor / 2,\r\n createResponse.id\r\n )\r\n ) {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Cancelled,\r\n 0\r\n );\r\n common\r\n .removeItem(createResponse.id, destinationAuthentication)\r\n .then(\r\n () =>\r\n resolve(\r\n common.generateEmptyCreationResponse(template.type)\r\n ),\r\n () =>\r\n resolve(common.generateEmptyCreationResponse(template.type))\r\n );\r\n } else {\r\n // Add the new item to the settings\r\n templateDictionary[template.itemId] = {\r\n itemId: createResponse.id\r\n };\r\n newItemTemplate.itemId = createResponse.id;\r\n\r\n // Set the appItemId manually to get around cases where the path was incorrectly set\r\n // in legacy deployments\r\n if (\r\n newItemTemplate.type === \"Web Mapping Application\" &&\r\n template.data\r\n ) {\r\n common.setProp(\r\n newItemTemplate,\r\n \"data.appItemId\",\r\n createResponse.id\r\n );\r\n }\r\n const postProcess: boolean = common.hasUnresolvedVariables(\r\n newItemTemplate.data\r\n );\r\n\r\n // Update the template again now that we have the new item id\r\n const originalURL = newItemTemplate.item.url;\r\n newItemTemplate = common.replaceInTemplate(\r\n newItemTemplate,\r\n templateDictionary\r\n );\r\n\r\n // Update relationships\r\n let relationshipsDef = Promise.resolve(\r\n [] as common.IStatusResponse[]\r\n );\r\n if (newItemTemplate.relatedItems) {\r\n // Templatize references in relationships obj\r\n const updatedRelatedItems = common.replaceInTemplate(\r\n common.templatizeIds(newItemTemplate.relatedItems),\r\n templateDictionary\r\n ) as common.IRelatedItems[];\r\n\r\n // Add the relationships\r\n relationshipsDef = common.addForwardItemRelationships(\r\n newItemTemplate.itemId,\r\n updatedRelatedItems,\r\n destinationAuthentication\r\n );\r\n }\r\n\r\n // Check for extra processing for web mapping application et al.\r\n let customProcDef: Promise<void>;\r\n if (\r\n template.type === \"Web Mapping Application\" &&\r\n template.data &&\r\n common.hasAnyKeyword(template, [\r\n \"WAB2D\",\r\n \"WAB3D\",\r\n \"Web AppBuilder\"\r\n ])\r\n ) {\r\n // If this is a Web AppBuilder application, we will create a Code Attachment for downloading\r\n customProcDef = webmappingapplication.fineTuneCreatedItem(\r\n template,\r\n newItemTemplate,\r\n templateDictionary,\r\n destinationAuthentication\r\n );\r\n } else if (template.type === \"Workforce Project\") {\r\n customProcDef = workforce.fineTuneCreatedItem(\r\n newItemTemplate,\r\n destinationAuthentication,\r\n templateDictionary\r\n );\r\n } else if (template.type === \"Notebook\") {\r\n customProcDef = notebook.fineTuneCreatedItem(\r\n template,\r\n newItemTemplate,\r\n templateDictionary,\r\n destinationAuthentication\r\n );\r\n } else if (originalURL !== newItemTemplate.item.url) {\r\n // For web mapping applications that are not Web AppBuilder apps\r\n customProcDef = new Promise<void>((resolve2, reject2) => {\r\n common\r\n .updateItemURL(\r\n createResponse.id,\r\n newItemTemplate.item.url,\r\n destinationAuthentication\r\n )\r\n .then(() => resolve2(), reject2);\r\n });\r\n } else {\r\n customProcDef = Promise.resolve(null);\r\n }\r\n\r\n Promise.all([relationshipsDef, customProcDef]).then(\r\n () => {\r\n // Interrupt process if progress callback returns `false`\r\n if (\r\n !itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Finished,\r\n template.estimatedDeploymentCostFactor / 2,\r\n createResponse.id\r\n )\r\n ) {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Cancelled,\r\n 0\r\n );\r\n common\r\n .removeItem(createResponse.id, destinationAuthentication)\r\n .then(\r\n () =>\r\n resolve(\r\n common.generateEmptyCreationResponse(template.type)\r\n ),\r\n () =>\r\n resolve(\r\n common.generateEmptyCreationResponse(template.type)\r\n )\r\n );\r\n } else {\r\n resolve({\r\n item: newItemTemplate,\r\n id: createResponse.id,\r\n type: newItemTemplate.type,\r\n postProcess: postProcess\r\n });\r\n }\r\n },\r\n () => {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Failed,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type)); // fails to deploy all resources to the item\r\n }\r\n );\r\n }\r\n },\r\n () => {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Failed,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type)); // fails to create item\r\n }\r\n );\r\n }\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 * as common from \"@esri/solution-common\";\r\n\r\n/**\r\n * Converts an workforce item to a template.\r\n *\r\n * @param itemTemplate template for the workforce project item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @returns templatized itemTemplate\r\n */\r\nexport function convertItemToTemplate(\r\n itemTemplate: common.IItemTemplate,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession\r\n): Promise<common.IItemTemplate> {\r\n return common.convertWorkforceItemToTemplate(itemTemplate, srcAuthentication);\r\n}\r\n\r\n/**\r\n * Gets the current user and updates the dispatchers service\r\n *\r\n * @param newlyCreatedItem Item to be created; n.b.: this item is modified\r\n * @param destinationAuthentication The session used to create the new item(s)\r\n * @returns A promise that will resolve with { \"success\" === true || false }\r\n */\r\nexport function fineTuneCreatedItem(\r\n newlyCreatedItem: common.IItemTemplate,\r\n destinationAuthentication: common.UserSession,\r\n templateDictionary: any\r\n): Promise<any> {\r\n return common.fineTuneCreatedWorkforceItem(\r\n newlyCreatedItem,\r\n destinationAuthentication,\r\n \"\",\r\n templateDictionary\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 {\r\n UserSession,\r\n IItemUpdate,\r\n jsonToBlob,\r\n updateItem\r\n} from \"@esri/solution-common\";\r\n\r\nexport function updateNotebookData(\r\n itemId: string,\r\n data: any,\r\n authentication: UserSession\r\n): Promise<any> {\r\n const updateOptions: IItemUpdate = {\r\n id: itemId,\r\n data: jsonToBlob(data)\r\n };\r\n return updateItem(updateOptions, authentication);\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\nimport * as common from \"@esri/solution-common\";\r\n// Need to import collectively to enable spying\r\nimport * as notebookHelpers from \"./helpers/notebook-helpers\";\r\n\r\n/**\r\n * Converts a notebook item into a template.\r\n *\r\n * @param solutionItemId The solution to contain the template\r\n * @param itemInfo Info about the item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements\r\n * @returns A promise that will resolve when the template has been created\r\n */\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession,\r\n templateDictionary: any\r\n): Promise<common.IItemTemplate> {\r\n // Delegate back to simple-types, which will in-turn delegate\r\n // to convertNotebookToTemplate at the correct point in the process\r\n // This is a temporary refactor step\r\n return notebookHelpers.convertItemToTemplate(\r\n solutionItemId,\r\n itemInfo,\r\n destAuthentication,\r\n srcAuthentication,\r\n templateDictionary\r\n );\r\n}\r\n\r\n// Delegate back to simple-types\r\n// This is a temporary refactor step\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 notebookHelpers.createItemFromTemplate(\r\n template,\r\n templateDictionary,\r\n destinationAuthentication,\r\n itemProgressCallback\r\n );\r\n}\r\n\r\n/**\r\n * Converts a Python Notebook item to a template.\r\n *\r\n * @param itemTemplate template for the Python Notebook\r\n * @returns templatized itemTemplate\r\n */\r\nexport function convertNotebookToTemplate(\r\n itemTemplate: common.IItemTemplate\r\n): common.IItemTemplate {\r\n // The templates data to process\r\n const data: any = itemTemplate.data;\r\n deleteProps(data);\r\n let dataString: string = JSON.stringify(data);\r\n\r\n const idTest: RegExp = /[0-9A-F]{32}/gim;\r\n\r\n if (data && idTest.test(dataString)) {\r\n const ids: string[] = dataString.match(idTest) as string[];\r\n const verifiedIds: string[] = [];\r\n ids.forEach(id => {\r\n if (verifiedIds.indexOf(id) === -1) {\r\n verifiedIds.push(id);\r\n\r\n // templatize the itemId--but only once per unique id\r\n const regEx = new RegExp(id, \"gm\");\r\n dataString = dataString.replace(regEx, \"{{\" + id + \".itemId}}\");\r\n\r\n // update the dependencies\r\n if (itemTemplate.dependencies.indexOf(id) === -1) {\r\n itemTemplate.dependencies.push(id);\r\n }\r\n }\r\n });\r\n itemTemplate.data = JSON.parse(dataString);\r\n }\r\n\r\n return itemTemplate;\r\n}\r\n\r\n/**\r\n * Remove interpreter and papermill props\r\n * \r\n * This function will update the data passed in by removing key props\r\n *\r\n * @param data The notebooks data object\r\n *\r\n */\r\nexport function deleteProps(\r\n data:any\r\n): void {\r\n /* istanbul ignore else */\r\n if (data) {\r\n const props: string[] = [\"metadata.interpreter\", \"metadata.papermill\"];\r\n common.deleteProps(data, props);\r\n (data.cells || []).forEach((cell: any) => {\r\n common.deleteProps(cell, props);\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Update the notebooks data\r\n *\r\n * @param originalTemplate The original template item\r\n * @param newlyCreatedItem The current item that may have unswapped variables\r\n * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies\r\n * @param authentication Credentials for the requests to the destination\r\n *\r\n * @returns A promise that will resolve once any updates have been made\r\n */\r\nexport function fineTuneCreatedItem(\r\n originalTemplate: common.IItemTemplate,\r\n newlyCreatedItem: common.IItemTemplate,\r\n templateDictionary: any,\r\n authentication: common.UserSession\r\n): Promise<void> {\r\n return new Promise<void>((resolve, reject) => {\r\n const updateOptions: common.IItemUpdate = {\r\n id: newlyCreatedItem.itemId,\r\n url: newlyCreatedItem.item.url,\r\n data: common.jsonToFile(\r\n newlyCreatedItem.data,\r\n newlyCreatedItem.itemId + \".ipynb\"\r\n )\r\n };\r\n common\r\n .updateItem(updateOptions, authentication)\r\n .then(() => resolve(null), reject);\r\n });\r\n}\r\n\r\n/**\r\n * Notebook specific post-processing actions\r\n *\r\n * @param {string} itemId The item ID\r\n * @param {string} type The template type\r\n * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} authentication The destination session info\r\n * @returns {Promise<any>}\r\n */\r\nexport function postProcess(\r\n itemId: string,\r\n type: string,\r\n itemInfos: any[],\r\n template: common.IItemTemplate,\r\n templates: common.IItemTemplate[],\r\n templateDictionary: any,\r\n authentication: common.UserSession\r\n): Promise<any> {\r\n return common.updateItemTemplateFromDictionary(\r\n itemId,\r\n templateDictionary,\r\n authentication\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 * as common from \"@esri/solution-common\";\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\n/**\r\n * Converts an AGOL OIC (Oriented Imagery Catalog) item to a template.\r\n *\r\n * @param itemTemplate Template for the OIC (Oriented Imagery Catalog) item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @returns Template for the solution item that contains key details for item reconstruction\r\n */\r\nexport function convertItemToTemplate(\r\n itemTemplate: common.IItemTemplate,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n // Extract dependencies\r\n _extractDependencies(itemTemplate, srcAuthentication).then(\r\n (results: any) => {\r\n itemTemplate.dependencies = results.dependencies;\r\n\r\n // Templatize the map layer ids after we've extracted them as dependencies\r\n /* istanbul ignore else */\r\n if (itemTemplate.data?.properties) {\r\n itemTemplate.data.properties.ServiceURL = _templatizeOicLayerUrl(\r\n itemTemplate.data.properties.ServiceURL,\r\n results.urlHash\r\n );\r\n itemTemplate.data.properties.OverviewURL = _templatizeOicLayerUrl(\r\n itemTemplate.data.properties.OverviewURL,\r\n results.urlHash\r\n );\r\n }\r\n\r\n resolve(itemTemplate);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n });\r\n}\r\n\r\n/**\r\n * Gets the ids of the dependencies of an AGOL OIC (Oriented Imagery Catalog) item.\r\n *\r\n * @param itemTemplate A OIC (Oriented Imagery Catalog) item whose dependencies are sought\r\n * @param authentication Credentials for any requests\r\n * @returns List of dependencies ids and url/itemId hash\r\n * @private\r\n */\r\nexport function _extractDependencies(\r\n itemTemplate: common.IItemTemplate,\r\n authentication: common.UserSession\r\n): Promise<any> {\r\n return new Promise<any>((resolve, reject) => {\r\n const dependencies: string[] = [];\r\n if (itemTemplate.data?.properties) {\r\n const layerURLs = [];\r\n /* istanbul ignore else */\r\n if (itemTemplate.data.properties.ServiceURL) {\r\n layerURLs.push(itemTemplate.data.properties.ServiceURL);\r\n }\r\n /* istanbul ignore else */\r\n if (\r\n itemTemplate.data.properties.OverviewURL &&\r\n itemTemplate.data.properties.OverviewURL !==\r\n itemTemplate.data.properties.ServiceURL\r\n ) {\r\n layerURLs.push(itemTemplate.data.properties.OverviewURL);\r\n }\r\n _getLayerIds(layerURLs, dependencies, authentication).then(\r\n results => {\r\n resolve(results);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve({\r\n dependencies: dependencies,\r\n urlHash: {}\r\n });\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Extracts the AGOL itemId for each layer in a list using the url.\r\n *\r\n * @param layerURLs List of OIC layer URLs\r\n * @param dependencies Current list of dependencies\r\n * @param authentication Credentials for any requests\r\n * @returns List of dependencies ids and url/itemId hash\r\n * @private\r\n */\r\nexport function _getLayerIds(\r\n layerURLs: string[],\r\n dependencies: string[],\r\n authentication: common.UserSession\r\n): Promise<any> {\r\n return new Promise<any>((resolve, reject) => {\r\n const urlHash: any = {};\r\n\r\n const options: any = {\r\n f: \"json\",\r\n authentication: authentication\r\n };\r\n const layerPromises: Array<Promise<any>> = [];\r\n const layerChecks: any = {};\r\n const filteredLayerURLs: any[] = layerURLs.filter(layerURL => {\r\n if (layerURL) {\r\n const results: any = /.+FeatureServer/g.exec(layerURL);\r\n const baseUrl: string =\r\n Array.isArray(results) && results.length > 0 ? results[0] : undefined;\r\n if (baseUrl) {\r\n // avoid redundant checks when we have a layer with subLayers\r\n /* istanbul ignore else */\r\n if (Object.keys(layerChecks).indexOf(baseUrl) < 0) {\r\n layerChecks[baseUrl] = common.rest_request(layerURL, options);\r\n }\r\n layerPromises.push(layerChecks[baseUrl]);\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n } else {\r\n return false;\r\n }\r\n });\r\n\r\n if (layerPromises.length > 0) {\r\n Promise.all(layerPromises).then(\r\n serviceResponses => {\r\n serviceResponses.forEach((serviceResponse, i) => {\r\n /* istanbul ignore else */\r\n if (common.getProp(serviceResponse, \"serviceItemId\")) {\r\n const id: string = serviceResponse.serviceItemId;\r\n /* istanbul ignore else */\r\n if (dependencies.indexOf(id) < 0) {\r\n dependencies.push(id);\r\n }\r\n urlHash[filteredLayerURLs[i]] = id;\r\n }\r\n });\r\n resolve({\r\n dependencies: dependencies,\r\n urlHash: urlHash\r\n });\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve({\r\n dependencies: dependencies,\r\n urlHash: urlHash\r\n });\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Templatizes the url and item id for a layer.\r\n *\r\n * @param layerURL OIC layer URL\r\n * @param urlHash Lookup object for analysis layers\r\n * @returns Templatized URL if layerURL is in the urlHash\r\n * @private\r\n */\r\nexport function _templatizeOicLayerUrl(layerURL: string, urlHash: any): string {\r\n let templatizedURL = layerURL;\r\n if (layerURL) {\r\n const id: any = urlHash[layerURL];\r\n if (id) {\r\n const layerId = layerURL.substr(layerURL.lastIndexOf(\"/\") + 1);\r\n templatizedURL = common.templatizeTerm(\r\n id,\r\n id,\r\n \".layer\" + layerId + \".url\"\r\n );\r\n }\r\n \r\n // replace everything up until /home with portalBaseUrl var and templatize the itemId\r\n templatizedURL = common.templatizeIds(\r\n templatizedURL.replace(/.+?(?=\\/home)/, \"{{portalBaseUrl}}\")\r\n );\r\n }\r\n return templatizedURL;\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 * as common from \"@esri/solution-common\";\r\nimport * as quickcaptureHelpers from \"./helpers/quickcapture-helpers\";\r\n\r\n//#region Publish Process ---------------------------------------------------------------------------------------//\r\n\r\n/**\r\n * Converts a Quick Capture item into a template.\r\n *\r\n * @param solutionItemId The solution to contain the template\r\n * @param itemInfo Info about the item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements\r\n * @returns A promise that will resolve when the template has been created\r\n */\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession,\r\n templateDictionary: any\r\n): Promise<common.IItemTemplate> {\r\n // Delegate back to simple-types, which will in-turn delegate\r\n // to convertNotebookToTemplate at the correct point in the process\r\n // This is a temporary refactor step\r\n return quickcaptureHelpers.convertItemToTemplate(\r\n solutionItemId,\r\n itemInfo,\r\n destAuthentication,\r\n srcAuthentication,\r\n templateDictionary\r\n );\r\n}\r\n\r\n/**\r\n * Converts an quick capture item to a template.\r\n *\r\n * @param itemTemplate template for the quick capture project item\r\n * @returns templatized itemTemplate\r\n */\r\nexport function convertQuickCaptureToTemplate(\r\n itemTemplate: common.IItemTemplate\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n // The templates data to process\r\n const data: any = itemTemplate.data;\r\n if (data && Array.isArray(data)) {\r\n let applicationRequest: Promise<any> = Promise.resolve(null);\r\n let applicationName: string = \"\";\r\n data.some((item: File) => {\r\n if (item.type === \"application/json\") {\r\n applicationName = item.name;\r\n applicationRequest = common.getBlobText(item);\r\n return true;\r\n }\r\n });\r\n\r\n applicationRequest.then(result => {\r\n // replace the template data array with the templatized application JSON\r\n itemTemplate.data = result\r\n ? {\r\n application: _templatizeApplication(\r\n JSON.parse(result),\r\n itemTemplate\r\n ),\r\n name: applicationName\r\n }\r\n : {};\r\n resolve(itemTemplate);\r\n }, reject);\r\n } else {\r\n resolve(itemTemplate);\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Templatizes key properties for a quick capture project and gathers item dependencies\r\n *\r\n * @param data the projects json\r\n * @param itemTemplate template for the quick capture project item\r\n * @returns templatized itemTemplate\r\n * @private\r\n */\r\nexport function _templatizeApplication(\r\n data: any,\r\n itemTemplate: common.IItemTemplate\r\n): any {\r\n // Quick Project item id\r\n _templatizeId(data, \"itemId\");\r\n\r\n // Set the admin email\r\n _templatizeAdminEmail(data);\r\n\r\n // datasource item id and url\r\n const dataSources: common.IQuickCaptureDatasource[] = data.dataSources;\r\n if (dataSources && Array.isArray(dataSources)) {\r\n dataSources.forEach(ds => {\r\n const id: string = ds.featureServiceItemId;\r\n if (id) {\r\n _updateDependencies(id, itemTemplate);\r\n _templatizeUrl(ds, \"featureServiceItemId\", \"url\");\r\n _templatizeId(ds, \"featureServiceItemId\");\r\n }\r\n });\r\n }\r\n return data;\r\n}\r\n\r\n/**\r\n * Templatize the email property\r\n *\r\n * @param data the quick capture application\r\n * @private\r\n */\r\nexport function _templatizeAdminEmail(data: any): void {\r\n if (common.getProp(data, \"preferences.adminEmail\")) {\r\n common.setProp(data, \"preferences.adminEmail\", \"{{user.email}}\");\r\n }\r\n}\r\n\r\n/**\r\n * Updates the templates dependencies list with unique item ids\r\n *\r\n * @param id the item id of the dependency\r\n * @param itemTemplate template for the quick capture project item\r\n * @returns templatized itemTemplate\r\n */\r\nexport function _updateDependencies(\r\n id: string,\r\n itemTemplate: common.IItemTemplate\r\n): void {\r\n if (itemTemplate.dependencies.indexOf(id) === -1) {\r\n itemTemplate.dependencies.push(id);\r\n }\r\n}\r\n\r\n/**\r\n * Templatize a url property\r\n *\r\n * @param obj the datasource object\r\n * @param idPath the path to the id property\r\n * @param urlPath the path to the url property\r\n * @private\r\n */\r\nexport function _templatizeUrl(\r\n obj: any,\r\n idPath: string,\r\n urlPath: string\r\n): void {\r\n const id: any = common.getProp(obj, idPath);\r\n const url: string = common.getProp(obj, urlPath);\r\n if (url) {\r\n const layerId = url.substr(url.lastIndexOf(\"/\") + 1);\r\n common.setProp(\r\n obj,\r\n urlPath,\r\n common.templatizeTerm(id, id, \".layer\" + layerId + \".url\")\r\n );\r\n }\r\n}\r\n\r\n/**\r\n * Templatize the item id property\r\n *\r\n * @param obj the datasource or object that contains the item id property\r\n * @param path the path to the id property\r\n * @private\r\n */\r\nexport function _templatizeId(obj: any, path: string): void {\r\n const id: any = common.getProp(obj, path);\r\n if (id) {\r\n common.setProp(obj, path, common.templatizeTerm(id, id, \".itemId\"));\r\n }\r\n}\r\n\r\n//#endregion\r\n\r\n//#region Deploy Process ---------------------------------------------------------------------------------------//\r\n\r\n// Delegate back to simple-types\r\n// This is a temporary refactor step\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 quickcaptureHelpers.createItemFromTemplate(\r\n template,\r\n templateDictionary,\r\n destinationAuthentication,\r\n itemProgressCallback\r\n );\r\n}\r\n\r\n/**\r\n * QuickCapture post-processing actions\r\n *\r\n * @param {string} itemId The item ID\r\n * @param {string} type The template type\r\n * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} authentication The destination session info\r\n * @returns Promise resolving to successfulness of update\r\n */\r\nexport function postProcess(\r\n itemId: string,\r\n type: string,\r\n itemInfos: any[],\r\n template: common.IItemTemplate,\r\n templates: common.IItemTemplate[],\r\n templateDictionary: any,\r\n authentication: common.UserSession\r\n): Promise<any> {\r\n return new Promise<any>((resolve, reject) => {\r\n template.data = common.replaceInTemplate(template.data, templateDictionary);\r\n common\r\n .updateItemTemplateFromDictionary(\r\n itemId,\r\n templateDictionary,\r\n authentication\r\n )\r\n .then(() => {\r\n common\r\n .updateItemResourceText(\r\n itemId,\r\n template.data.name,\r\n JSON.stringify(template.data.application),\r\n authentication\r\n )\r\n .then(resolve, reject);\r\n }, reject);\r\n });\r\n}\r\n\r\n//#endregion\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 * as common from \"@esri/solution-common\";\r\n\r\n/**\r\n * The portion of a Webmap URL between the server and the map id.\r\n *\r\n * @private\r\n */\r\nconst WEBMAP_APP_URL_PART: string = \"home/webmap/viewer.html?webmap=\";\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\n/**\r\n * Converts an AGOL webmap item to a template.\r\n *\r\n * @param itemTemplate Template for the webmap item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @returns Template for the solution item that contains key details for item reconstruction\r\n */\r\nexport function convertItemToTemplate(\r\n itemTemplate: common.IItemTemplate,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n // Templatize the app URL\r\n itemTemplate.item.url = itemTemplate.item.url ?\r\n common.checkUrlPathTermination(common.placeholder(common.SERVER_NAME)) +\r\n WEBMAP_APP_URL_PART +\r\n itemTemplate.item.id : itemTemplate.item.url; // templatized id\r\n\r\n // Extract dependencies\r\n _extractDependencies(itemTemplate, srcAuthentication).then(\r\n (results: any) => {\r\n itemTemplate.dependencies = results.dependencies;\r\n\r\n // Templatize the map layer ids after we've extracted them as dependencies\r\n if (itemTemplate.data) {\r\n _templatizeWebmapLayerIdsAndUrls(\r\n itemTemplate.data.operationalLayers,\r\n results.urlHash\r\n );\r\n _templatizeWebmapLayerIdsAndUrls(\r\n itemTemplate.data.tables,\r\n results.urlHash\r\n );\r\n\r\n // Exclude intialState\r\n _excludeInitialState(itemTemplate.data);\r\n }\r\n\r\n resolve(itemTemplate);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n });\r\n}\r\n\r\n/**\r\n * Gets the ids of the dependencies of an AGOL webmap item.\r\n *\r\n * @param itemTemplate A webmap item whose dependencies are sought\r\n * @param authentication Credentials for any requests\r\n * @returns List of dependencies ids and url/itemId hash\r\n * @private\r\n */\r\nexport function _extractDependencies(\r\n itemTemplate: common.IItemTemplate,\r\n authentication: common.UserSession\r\n): Promise<any> {\r\n return new Promise<any>((resolve, reject) => {\r\n const dependencies: string[] = [];\r\n if (itemTemplate.data) {\r\n const layers: any[] = itemTemplate.data.operationalLayers || [];\r\n const tables: any[] = itemTemplate.data.tables || [];\r\n const layersAndTables: any[] = layers.concat(tables);\r\n _getLayerIds(layersAndTables, dependencies, authentication).then(\r\n results => {\r\n resolve(results);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve({\r\n dependencies: dependencies,\r\n urlHash: {}\r\n });\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Remove the initialState prop from webmaps saved from the new map viewer.\r\n * This allows the map to use the item extent property that we templatize.\r\n *\r\n * Added for issue #662\r\n *\r\n * @param data the data for the web maps item template\r\n * @returns void\r\n * @private\r\n */\r\nexport function _excludeInitialState(data: any): void {\r\n common.deleteProp(data, \"initialState\");\r\n}\r\n\r\n/**\r\n * Extracts the AGOL itemId for each layer or table object in a list using the url.\r\n *\r\n * @param layerList List of map layers or tables\r\n * @param dependencies Current list of dependencies\r\n * @param authentication Credentials for any requests\r\n * @returns List of dependencies ids and url/itemId hash\r\n * @private\r\n */\r\nexport function _getLayerIds(\r\n layerList: any[],\r\n dependencies: string[],\r\n authentication: common.UserSession\r\n): Promise<any> {\r\n return new Promise<any>((resolve, reject) => {\r\n const urlHash: any = {};\r\n\r\n const options: any = {\r\n f: \"json\",\r\n authentication: authentication\r\n };\r\n const layerPromises: Array<Promise<any>> = [];\r\n const layerChecks: any = {};\r\n const layers: any[] = layerList.filter(layer => {\r\n if (layer.url && layer.url.indexOf(\"{{velocityUrl}}\") < 0) {\r\n const results: any = /.+FeatureServer/g.exec(layer.url);\r\n const baseUrl: string =\r\n Array.isArray(results) && results.length > 0 ? results[0] : undefined;\r\n if (baseUrl) {\r\n // avoid redundant checks when we have a layer with subLayers\r\n if (Object.keys(layerChecks).indexOf(baseUrl) < 0) {\r\n layerChecks[baseUrl] = common.rest_request(layer.url, options);\r\n }\r\n layerPromises.push(layerChecks[baseUrl]);\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n } else {\r\n return false;\r\n }\r\n });\r\n\r\n if (layerPromises.length > 0) {\r\n Promise.all(layerPromises).then(\r\n serviceResponses => {\r\n serviceResponses.forEach((serviceResponse, i) => {\r\n if (common.getProp(serviceResponse, \"serviceItemId\")) {\r\n const id: string = serviceResponse.serviceItemId;\r\n if (dependencies.indexOf(id) < 0) {\r\n dependencies.push(id);\r\n }\r\n urlHash[layers[i].url] = id;\r\n }\r\n });\r\n resolve({\r\n dependencies: dependencies,\r\n urlHash: urlHash\r\n });\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve({\r\n dependencies: dependencies,\r\n urlHash: urlHash\r\n });\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Templatizes the url and item id for layers or tables within the webmap.\r\n *\r\n * @param layerList List of map layers or tables\r\n * @param urlHash Lookup object for analysis layers\r\n * @returns void\r\n * @private\r\n */\r\nexport function _templatizeWebmapLayerIdsAndUrls(\r\n layerList = [] as any[],\r\n urlHash: any\r\n): void {\r\n layerList.forEach((layer: any) => {\r\n if (layer.url) {\r\n const layerId = layer.url.substr(\r\n (layer.url as string).lastIndexOf(\"/\") + 1\r\n );\r\n const id: any =\r\n Object.keys(urlHash).indexOf(layer.url) > -1\r\n ? urlHash[layer.url]\r\n : undefined;\r\n if (id) {\r\n layer.url = common.templatizeTerm(id, id, \".layer\" + layerId + \".url\");\r\n layer.itemId = common.templatizeTerm(\r\n id,\r\n id,\r\n \".layer\" + layerId + \".itemId\"\r\n );\r\n }\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Templatize field references.\r\n *\r\n * @param solutionTemplate The solution item template\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns The solutionTemplate with templatized field references\r\n */\r\nexport function postProcessFieldReferences(\r\n solutionTemplate: common.IItemTemplate,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): common.IItemTemplate {\r\n const paths: string[] = [\r\n \"data.operationalLayers\",\r\n \"data.tables\",\r\n \"data.applicationProperties.viewing.search.layers\"\r\n ];\r\n paths.forEach(p => _templatizeProperty(solutionTemplate, datasourceInfos, p));\r\n return solutionTemplate;\r\n}\r\n\r\n/**\r\n * Templatize field references.\r\n *\r\n * @param solutionTemplate The solution item template\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @param path A string path to the object property to templatize\r\n * @private\r\n */\r\nexport function _templatizeProperty(\r\n solutionTemplate: common.IItemTemplate,\r\n datasourceInfos: common.IDatasourceInfo[],\r\n path: string\r\n): void {\r\n const objs: any[] = common.getProp(solutionTemplate, path);\r\n if (objs) {\r\n common.setProp(solutionTemplate, path, _templatize(objs, datasourceInfos));\r\n }\r\n}\r\n\r\n/**\r\n * Templatize field references.\r\n *\r\n * @param objs Can be operationalLayers or tables or appProperties search layers\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns updated instances of the objects\r\n * @private\r\n */\r\nexport function _templatize(\r\n objs: any[],\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): any[] {\r\n objs.forEach(obj => {\r\n const ds: common.IDatasourceInfo = _getDatasourceInfo(obj, datasourceInfos);\r\n if (ds) {\r\n const fieldNames: string[] = ds.fields.map(f => f.name);\r\n\r\n common._templatizePopupInfo(obj, ds, ds.basePath, ds.itemId, fieldNames);\r\n\r\n common._templatizeDefinitionEditor(obj, ds.basePath, fieldNames);\r\n\r\n if (obj.layerDefinition) {\r\n common._templatizeDrawingInfo(\r\n obj.layerDefinition,\r\n ds.basePath,\r\n fieldNames\r\n );\r\n\r\n common._templatizeDefinitionExpression(\r\n obj.layerDefinition,\r\n ds.basePath,\r\n fieldNames\r\n );\r\n }\r\n\r\n // used for applicationProperties search layers\r\n const fieldName: any = common.getProp(obj, \"field.name\");\r\n if (fieldName) {\r\n common.setProp(\r\n obj,\r\n \"field.name\",\r\n common._templatizeFieldName(fieldName, obj, ds.itemId, ds.basePath)\r\n );\r\n }\r\n }\r\n });\r\n\r\n return objs;\r\n}\r\n\r\n/**\r\n * Get datasourceInfo by map layer id\r\n *\r\n * @param obj Can be operationalLayer or table or appProperties search layer\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns datasourceInfo for the given object id\r\n * @private\r\n */\r\nexport function _getDatasourceInfo(\r\n obj: any,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): any {\r\n let datasourceInfo: any;\r\n datasourceInfos.some(ds => {\r\n if (ds.ids.indexOf(obj.id) > -1) {\r\n datasourceInfo = ds;\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n });\r\n return datasourceInfo;\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\nimport * as common from \"@esri/solution-common\";\r\nimport * as dashboard from \"../dashboard\";\r\nimport * as notebook from \"../notebook\";\r\nimport * as oic from \"../oic\";\r\nimport * as quickcapture from \"../quickcapture\";\r\nimport * as webmap from \"../webmap\";\r\nimport * as webmappingapplication from \"../webmappingapplication\";\r\nimport * as workforce from \"../workforce\";\r\n\r\n/**\r\n * Converts an item into a template.\r\n *\r\n * @param solutionItemId The solution to contain the template\r\n * @param itemInfo Info about the item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements\r\n *\r\n * @returns A promise that will resolve when the template has been created\r\n */\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession,\r\n templateDictionary: any\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n // Init template\r\n const itemTemplate: common.IItemTemplate = common.createInitializedItemTemplate(\r\n itemInfo\r\n );\r\n\r\n // Templatize item info property values\r\n itemTemplate.item.id = common.templatizeTerm(\r\n itemTemplate.item.id,\r\n itemTemplate.item.id,\r\n \".itemId\"\r\n );\r\n\r\n // Request related items\r\n const relatedPromise = common.getItemRelatedItemsInSameDirection(\r\n itemTemplate.itemId,\r\n \"forward\",\r\n srcAuthentication\r\n );\r\n\r\n // Perform type-specific handling\r\n let dataPromise = Promise.resolve({});\r\n switch (itemInfo.type) {\r\n case \"Dashboard\":\r\n case \"Feature Collection\":\r\n case \"Feature Service\":\r\n case \"Hub Initiative\":\r\n case \"Hub Page\":\r\n case \"Hub Site Application\":\r\n case \"Insights Model\":\r\n case \"Oriented Imagery Catalog\":\r\n case \"Project Package\":\r\n case \"Workforce Project\":\r\n case \"Web Map\":\r\n case \"Web Mapping Application\":\r\n case \"Web Scene\":\r\n case \"Notebook\":\r\n dataPromise = new Promise(resolveJSON => {\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n common\r\n .getItemDataAsJson(itemTemplate.itemId, srcAuthentication)\r\n .then(json => resolveJSON(json));\r\n });\r\n break;\r\n case \"Form\":\r\n dataPromise = common.getItemDataAsFile(\r\n itemTemplate.itemId,\r\n itemTemplate.item.name,\r\n srcAuthentication\r\n );\r\n break;\r\n case \"QuickCapture Project\":\r\n dataPromise = common.getItemResourcesFiles(\r\n itemTemplate.itemId,\r\n srcAuthentication\r\n );\r\n break;\r\n }\r\n\r\n // Errors are handled as resolved empty values; this means that there's no `reject` clause to handle, hence:\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n Promise.all([dataPromise, relatedPromise]).then(responses => {\r\n const [itemDataResponse, relatedItemsResponse] = responses;\r\n\r\n // need to pre-process for velocity urls before they could be templatized by other processors\r\n itemTemplate.data = common.updateVelocityReferences(\r\n itemDataResponse,\r\n itemInfo.type,\r\n templateDictionary\r\n );\r\n const relationships = relatedItemsResponse;\r\n\r\n // Save the mappings to related items & add those items to the dependencies, but not WMA Code Attachments\r\n itemTemplate.dependencies = [] as string[];\r\n itemTemplate.relatedItems = [] as common.IRelatedItems[];\r\n\r\n relationships.forEach(relationship => {\r\n /* istanbul ignore else */\r\n if (relationship.relationshipType !== \"WMA2Code\") {\r\n itemTemplate.relatedItems.push(relationship);\r\n relationship.relatedItemIds.forEach(relatedItemId => {\r\n if (itemTemplate.dependencies.indexOf(relatedItemId) < 0) {\r\n itemTemplate.dependencies.push(relatedItemId);\r\n }\r\n });\r\n }\r\n });\r\n\r\n let wrapupPromise = Promise.resolve(null);\r\n let templateModifyingPromise = Promise.resolve(itemTemplate);\r\n switch (itemInfo.type) {\r\n case \"Dashboard\":\r\n dashboard.convertItemToTemplate(itemTemplate);\r\n break;\r\n case \"Form\":\r\n // Store the form's data in the solution resources, not in template\r\n itemTemplate.data = null;\r\n\r\n // Store form data\r\n if (itemDataResponse) {\r\n const originalFilename =\r\n itemTemplate.item.name || (itemDataResponse as File).name;\r\n const filename =\r\n originalFilename && originalFilename !== \"undefined\"\r\n ? originalFilename\r\n : `${itemTemplate.itemId}.zip`;\r\n itemTemplate.item.name = filename;\r\n const storageName = common.convertItemResourceToStorageResource(\r\n itemTemplate.itemId,\r\n filename,\r\n common.SolutionTemplateFormatVersion,\r\n common.SolutionResourceType.data\r\n );\r\n wrapupPromise = new Promise<void>(\r\n (resolveDataStorage, rejectDataStorage) => {\r\n common\r\n .addResourceFromBlob(\r\n itemDataResponse,\r\n solutionItemId,\r\n storageName.folder,\r\n filename,\r\n destAuthentication\r\n )\r\n .then(() => {\r\n // Update the template's resources\r\n itemTemplate.resources.push(\r\n storageName.folder + \"/\" + storageName.filename\r\n );\r\n resolveDataStorage();\r\n }, rejectDataStorage);\r\n }\r\n );\r\n }\r\n break;\r\n case \"Notebook\":\r\n notebook.convertNotebookToTemplate(itemTemplate);\r\n break;\r\n case \"Oriented Imagery Catalog\":\r\n templateModifyingPromise = oic.convertItemToTemplate(\r\n itemTemplate,\r\n destAuthentication,\r\n srcAuthentication\r\n );\r\n break;\r\n case \"Web Map\":\r\n case \"Web Scene\":\r\n templateModifyingPromise = webmap.convertItemToTemplate(\r\n itemTemplate,\r\n destAuthentication,\r\n srcAuthentication\r\n );\r\n break;\r\n case \"Web Mapping Application\":\r\n if (itemDataResponse) {\r\n templateModifyingPromise = webmappingapplication.convertItemToTemplate(\r\n itemTemplate,\r\n destAuthentication,\r\n srcAuthentication\r\n );\r\n }\r\n break;\r\n case \"Workforce Project\":\r\n templateModifyingPromise = workforce.convertItemToTemplate(\r\n itemTemplate,\r\n destAuthentication,\r\n srcAuthentication\r\n );\r\n break;\r\n case \"QuickCapture Project\":\r\n templateModifyingPromise = quickcapture.convertQuickCaptureToTemplate(\r\n itemTemplate\r\n );\r\n break;\r\n }\r\n\r\n wrapupPromise.then(\r\n () => {\r\n templateModifyingPromise.then(resolve, err =>\r\n reject(common.fail(err))\r\n );\r\n },\r\n err => reject(common.fail(err))\r\n );\r\n });\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 simple item types.\r\n *\r\n * @module simple-types\r\n */\r\n\r\nimport * as dashboard from \"./dashboard\";\r\nimport * as webmap from \"./webmap\";\r\nimport * as webmappingapplication from \"./webmappingapplication\";\r\n\r\nimport {\r\n ICreateItemFromTemplateResponse,\r\n IDatasourceInfo,\r\n IItemProgressCallback,\r\n IItemTemplate,\r\n IUpdateItemResponse,\r\n updateItemTemplateFromDictionary,\r\n UserSession\r\n} from \"@esri/solution-common\";\r\n\r\n// Need to import collectively to enable spying\r\nimport * as simpleTypeHelpers from \"./helpers/simple-type-helpers\";\r\n\r\n/**\r\n * Converts an item into a template.\r\n *\r\n * @param solutionItemId The solution to contain the template\r\n * @param itemInfo Info about the item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements\r\n * @returns A promise that will resolve when the template has been created\r\n */\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any,\r\n destAuthentication: UserSession,\r\n srcAuthentication: UserSession,\r\n templateDictionary: any\r\n): Promise<IItemTemplate> {\r\n return simpleTypeHelpers.convertItemToTemplate(\r\n solutionItemId,\r\n itemInfo,\r\n destAuthentication,\r\n srcAuthentication,\r\n templateDictionary\r\n );\r\n}\r\n\r\n/**\r\n * Delegate to simpleType creator\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 return simpleTypeHelpers.createItemFromTemplate(\r\n template,\r\n templateDictionary,\r\n destinationAuthentication,\r\n itemProgressCallback\r\n );\r\n}\r\n\r\n/**\r\n * Templatizes field references within specific template types.\r\n * Currently only handles web mapping applications\r\n *\r\n * @param template A solution template\r\n * @param datasourceInfos A list of objects that store key datasource info used to templatizing field references\r\n * @param type The item type\r\n * @returns The updated solution template\r\n */\r\nexport function postProcessFieldReferences(\r\n solutionTemplate: IItemTemplate,\r\n datasourceInfos: IDatasourceInfo[],\r\n type: string\r\n): IItemTemplate {\r\n switch (type) {\r\n case \"Web Mapping Application\":\r\n webmappingapplication.postProcessFieldReferences(\r\n solutionTemplate,\r\n datasourceInfos\r\n );\r\n break;\r\n case \"Dashboard\":\r\n dashboard.postProcessFieldReferences(solutionTemplate, datasourceInfos);\r\n break;\r\n case \"Web Map\":\r\n webmap.postProcessFieldReferences(solutionTemplate, datasourceInfos);\r\n break;\r\n }\r\n return solutionTemplate;\r\n}\r\n\r\n/**\r\n * Simple Type post-processing actions\r\n *\r\n * @param {string} itemId The item ID\r\n * @param {string} type The template type\r\n * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} authentication The destination session info\r\n * @returns Promise resolving to successfulness of update\r\n */\r\nexport function postProcess(\r\n itemId: string,\r\n type: string,\r\n itemInfos: any[],\r\n template: IItemTemplate,\r\n templates: IItemTemplate[],\r\n templateDictionary: any,\r\n authentication: UserSession\r\n): Promise<IUpdateItemResponse> {\r\n return updateItemTemplateFromDictionary(\r\n itemId,\r\n templateDictionary,\r\n authentication\r\n );\r\n}\r\n"],"names":["convertItemToTemplate","itemTemplate","forEach","path","objs","common","getProp","Array","isArray","obj","type","dependencies","indexOf","itemId","push","templatizeTerm","datasets","dataset","layerId","dataSource","undefined","_getDatasourceDependencies","_extractDependencies","postProcessFieldReferences","solutionTemplate","datasourceInfos","updatePaths","cleanLayerBasedItemId","cleanLayerId","some","ds","_updateReferences","id","dashboardLayerId","split","ids","_updateDatasourceReferences","setProp","map","_obj","events","event","_event","actions","action","_action","fieldMap","targetId","datasourceInfo","_getDatasourceInfo","fields","basePath","m","_m","targetName","templatizeFieldReferences","_dataset","_templatizeByDatasource","_templatize","info","di","dashboardWidgetId","hasRef","references","matches","destAuthentication","srcAuthentication","Promise","resolve","reject","portalUrl","item","url","templatizedUrl","iSep","placeholder","SERVER_NAME","substring","lastIndexOf","replace","model","processor","_getGenericWebAppDependencies","hasAnyKeyword","_getWABDependencies","paths","_templatizeIdPath","_templatizeIdPaths","setValues","GEOMETRY_SERVER_NAME","authentication","dataSources","Object","keys","length","pendingRequests","k","substr","urlResults","findUrls","resolveReq","rejectReq","handleServiceRequests","serviceRequests","requestUrls","testString","then","response","e","fail","all","templatizeDatasources","templatizeWidgets","_itemTemplate","updatedItemTemplate","widgetPath","values","JSON","stringify","parse","templatizeValues","_updatedItemTemplate","isOnScreen","widgets","widget","config","sWidgets","objString","i","serviceResponses","serviceResponse","serviceTemplate","serviceItemId","hasOwnProperty","replaceUrl","options","f","results","match","NA_SERVER_NAME","GEOCODE_SERVER_NAME","rest_request","newUrl","validateFullUrl","enforceFullUrl","re","RegExp","base","subString","getProps","deps","v","_templatizeObject","objects","updateKeyObjects","templatizeKeys","name","_templatizeObjectArray","hasDatasources","filter","urlTest","isNaN","hasMapLayerId","test","_templatizeParentByURL","_templatizeParentByWebMapLayerId","_prioritizedTests","replaceOrder","_getSortOrder","sort","a","b","_getReplaceOrder","layerUrlTest","clone","c","idTest","parsedProp","error","createItemFromTemplate","template","templateDictionary","destinationAuthentication","itemProgressCallback","EItemProgressStatus","Started","newItemTemplate","cloneObject","replaceInTemplate","data","thumbnail","createItemWithData","folderId","createResponse","Created","estimatedDeploymentCostFactor","postProcess","hasUnresolvedVariables","originalURL","customProcDef","relationshipsDef","relatedItems","updatedRelatedItems","templatizeIds","addForwardItemRelationships","originalTemplate","newlyCreatedItem","updateOptions","updateDef","updateItem","itemInfo","tags","title","typeKeywords","relationshipType","originItemId","checkUrlPathTermination","createItemWithDataDef","webmappingapplication.fineTuneCreatedItem","fineTuneCreatedWorkforceItem","workforce.fineTuneCreatedItem","notebook.fineTuneCreatedItem","resolve2","reject2","updateItemURL","Finished","Cancelled","removeItem","generateEmptyCreationResponse","Failed","Ignored","jsonToBlob","convertNotebookToTemplate","deleteProps","dataString","verifiedIds","regEx","props","cells","cell","fineTuneCreatedItem","jsonToFile","solutionItemId","notebookHelpers.convertItemToTemplate","notebookHelpers.createItemFromTemplate","itemInfos","templates","updateItemTemplateFromDictionary","properties","layerURLs","ServiceURL","OverviewURL","urlHash","layerPromises","layerChecks","filteredLayerURLs","layerURL","exec","baseUrl","_getLayerIds","_templatizeOicLayerUrl","templatizedURL","convertQuickCaptureToTemplate","applicationRequest","applicationName","getBlobText","result","application","_templatizeApplication","_templatizeId","_templatizeAdminEmail","featureServiceItemId","_updateDependencies","_templatizeUrl","idPath","urlPath","quickcaptureHelpers.convertItemToTemplate","quickcaptureHelpers.createItemFromTemplate","updateItemResourceText","layers","operationalLayers","tables","layerList","layer","concat","_templatizeWebmapLayerIdsAndUrls","deleteProp","p","fieldNames","_templatizePopupInfo","_templatizeDefinitionEditor","layerDefinition","_templatizeDrawingInfo","_templatizeDefinitionExpression","fieldName","_templatizeFieldName","_templatizeProperty","createInitializedItemTemplate","relatedPromise","getItemRelatedItemsInSameDirection","dataPromise","resolveJSON","getItemDataAsJson","json","getItemDataAsFile","getItemResourcesFiles","responses","itemDataResponse","relatedItemsResponse","updateVelocityReferences","relationships","relationship","relatedItemIds","relatedItemId","wrapupPromise","templateModifyingPromise","dashboard.convertItemToTemplate","originalFilename","filename","storageName","convertItemResourceToStorageResource","SolutionTemplateFormatVersion","SolutionResourceType","resolveDataStorage","rejectDataStorage","addResourceFromBlob","folder","resources","notebook.convertNotebookToTemplate","oic.convertItemToTemplate","webmap.convertItemToTemplate","webmappingapplication.convertItemToTemplate","convertWorkforceItemToTemplate","workforce.convertItemToTemplate","quickcapture.convertQuickCaptureToTemplate","err","simpleTypeHelpers.convertItemToTemplate","simpleTypeHelpers.createItemFromTemplate","webmappingapplication.postProcessFieldReferences","dashboard.postProcessFieldReferences","webmap.postProcessFieldReferences"],"mappings":";;;;;;;;;;;;;;;;;uoBAiFgBA,EACdC,GAEA,gBAYAA,GA8BA,MA3B8B,CAC5B,eACA,6BACA,2BACA,sBAGUC,SAAQC,IAClB,MAAMC,EAA2BC,EAAOC,QAAQL,EAAcE,GAC1DI,MAAMC,QAAQJ,IAChBA,EAAKF,SAAQO,IAEM,cAAbA,EAAIC,OAEFT,EAAaU,aAAaC,QAAQH,EAAII,QAAU,GAClDZ,EAAaU,aAAaG,KAAKL,EAAII,QAErCJ,EAAII,OAASR,EAAOU,eAAeN,EAA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IAAK,WACHI,EAAmCvU,GACnC,MACF,IAAK,2BACH0T,EAA2Bc,EACzBxU,EACAgE,EACAC,GAEF,MACF,IAAK,UACL,IAAK,YACHyP,EAA2Be,EACzBzU,EACAgE,EACAC,GAEF,MACF,IAAK,0BACCiP,IACFQ,EAA2BgB,EACzB1U,EACAgE,EACAC,IAGJ,MACF,IAAK,oBACHyP,WNlLR1T,EACAgE,EACAC,GAEA,OAAO7D,EAAOuU,+BAA+B3U,EAAciE,GM8KxB2Q,CACzB5U,EACAgE,EACAC,GAEF,MACF,IAAK,uBACHyP,EAA2BmB,EACzB7U,GAKNyT,EAAchN,MACZ,KACEiN,EAAyBjN,KAAKtC,GAAS2Q,GACrC1Q,EAAOhE,EAAOwG,KAAKkO,SAGvBA,GAAO1Q,EAAOhE,EAAOwG,KAAKkO,sKC9KhC7F,EACAhC,EACAjJ,EACAC,EACAmH,GAEA,OAAO2J,EACL9F,EACAhC,EACAjJ,EACAC,EACAmH,oCAaFD,EACAC,EACAC,EACAC,GAEA,OAAO0J,EACL7J,EACAC,EACAC,EACAC,wCAcF/J,EACAC,EACAf,GAEA,OAAQA,GACN,IAAK,0BACHwU,EACE1T,EACAC,GAEF,MACF,IAAK,YACH0T,EAAqC3T,EAAkBC,GACvD,MACF,IAAK,UACH2T,EAAkC5T,EAAkBC,GAGxD,OAAOD,wBAcPX,EACAH,EACA2O,EACAjE,EACAkE,EACAjE,EACA3F,GAEA,OAAO6J,mCACL1O,EACAwK,EACA3F"}
|
|
1
|
+
{"version":3,"file":"simple-types.umd.min.js","sources":["../../src/dashboard.ts","../../src/webmappingapplication.ts","../../src/helpers/create-item-from-template.ts","../../src/workforce.ts","../../src/helpers/update-notebook-data.ts","../../src/notebook.ts","../../src/oic.ts","../../src/quickcapture.ts","../../src/webmap.ts","../../src/helpers/convert-item-to-template.ts","../../src/simple-types.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 * as common from \"@esri/solution-common\";\r\n\r\n/**\r\n * The relevant elements of a Dashboard widget.\r\n *\r\n * @private\r\n */\r\ninterface IDashboardWidget {\r\n /**\r\n * AGOL item id for some widget types\r\n */\r\n itemId: string;\r\n /**\r\n * Dashboard widget type\r\n */\r\n type: string;\r\n /**\r\n * Dashboard widget datasets if any\r\n * These can be relative references to layers in map a map widget or external datasources\r\n */\r\n datasets?: IDashboardDataset[];\r\n}\r\n\r\n/**\r\n * The relevant elements of a dashboards dataset\r\n *\r\n * @private\r\n */\r\ninterface IDashboardDataset {\r\n /**\r\n * These can be relative references to layers in map a map widget or external datasources\r\n */\r\n dataSource: IDashboardDatasource;\r\n /**\r\n * Dashboard dataset type...we are only concerend with service datasets\r\n */\r\n type: string;\r\n}\r\n\r\n/**\r\n * The relevant datasource properties that describe a dataset\r\n *\r\n * @private\r\n */\r\ninterface IDashboardDatasource {\r\n /**\r\n * When it's an external datasource it will contain the portal itemId\r\n * as well as the individual layerId\r\n */\r\n itemId?: string;\r\n layerId?: any;\r\n /**\r\n * When it's a datasource from a map widget it will contain a reltive path\r\n * DashboardMapId#OperationalLayerId\r\n * For example: b38e032d-bf0c-426f-8036-b86341eb3693#TestLayerForDashBoardMap_632\r\n */\r\n id?: string;\r\n}\r\n\r\n/**\r\n * Converts a dashboard item to a template.\r\n *\r\n * @param itemTemplate Template for the dashboard item\r\n * @returns templatized itemTemplate\r\n */\r\nexport function convertItemToTemplate(\r\n itemTemplate: common.IItemTemplate\r\n): common.IItemTemplate {\r\n return _extractDependencies(itemTemplate);\r\n}\r\n\r\n/**\r\n * Templatizes all itemIds and updates the dependency array\r\n *\r\n * @param itemTemplate Template for the dashboard item\r\n * @returns The updated itemTemplate\r\n * @private\r\n * @private\r\n */\r\nexport function _extractDependencies(\r\n itemTemplate: common.IItemTemplate\r\n): common.IItemTemplate {\r\n // get dependencies from any\r\n const updatePaths: string[] = [\r\n \"data.widgets\",\r\n \"data.headerPanel.selectors\",\r\n \"data.leftPanel.selectors\",\r\n \"data.urlParameters\"\r\n ];\r\n\r\n updatePaths.forEach(path => {\r\n const objs: IDashboardWidget[] = common.getProp(itemTemplate, path);\r\n if (Array.isArray(objs)) {\r\n objs.forEach(obj => {\r\n /* istanbul ignore else */\r\n if (obj.type === \"mapWidget\") {\r\n /* istanbul ignore else */\r\n if (itemTemplate.dependencies.indexOf(obj.itemId) < 0) {\r\n itemTemplate.dependencies.push(obj.itemId);\r\n }\r\n obj.itemId = common.templatizeTerm(obj.itemId, obj.itemId, \".itemId\");\r\n }\r\n /* istanbul ignore else */\r\n if (Array.isArray(obj.datasets)) {\r\n _getDatasourceDependencies(obj, itemTemplate);\r\n }\r\n });\r\n }\r\n });\r\n\r\n return itemTemplate;\r\n}\r\n\r\n/**\r\n * Templatize datasource itemIds and update the dependency array\r\n *\r\n * @param obj A widget, selector, or urlParameter that contains a datasets collection\r\n * @param itemTemplate Template for the dashboard item\r\n * @private\r\n */\r\nexport function _getDatasourceDependencies(\r\n obj: any,\r\n itemTemplate: common.IItemTemplate\r\n): void {\r\n obj.datasets.forEach((dataset: IDashboardDataset) => {\r\n // when the datasource has an itemId is an external datasource\r\n const itemId: string = common.getProp(dataset, \"dataSource.itemId\");\r\n if (itemId) {\r\n if (itemTemplate.dependencies.indexOf(itemId) < 0) {\r\n itemTemplate.dependencies.push(itemId);\r\n }\r\n const layerId: number = common.getProp(dataset, \"dataSource.layerId\");\r\n dataset.dataSource.itemId = common.templatizeTerm(\r\n itemId,\r\n itemId,\r\n layerId !== undefined ? \".layer\" + layerId + \".itemId\" : \".itemId\"\r\n );\r\n /* istanbul ignore else */\r\n if (layerId !== undefined) {\r\n dataset.dataSource.layerId = common.templatizeTerm(\r\n itemId,\r\n itemId,\r\n \".layer\" + layerId + \".layerId\"\r\n );\r\n }\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Templatize field references for datasources and widgets.\r\n *\r\n * @param solutionTemplate The solution item template\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns The solutionTemplate with templatized field references\r\n */\r\nexport function postProcessFieldReferences(\r\n solutionTemplate: common.IItemTemplate,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): common.IItemTemplate {\r\n const updatePaths: string[] = [\r\n \"data.widgets\",\r\n \"data.headerPanel.selectors\",\r\n \"data.leftPanel.selectors\",\r\n \"data.urlParameters\"\r\n ];\r\n\r\n // dashboards reference datasets from other widgets\r\n // add reference IDs to the appropriate datasourceInfos\r\n updatePaths.forEach(path => {\r\n const objs: any = common.getProp(solutionTemplate, path);\r\n _updateDatasourceReferences(objs, datasourceInfos);\r\n });\r\n\r\n // after we know the potential references go ahead and templatize\r\n updatePaths.forEach(path => {\r\n _templatize(solutionTemplate, path, datasourceInfos);\r\n });\r\n\r\n return solutionTemplate;\r\n}\r\n\r\n/**\r\n * Add all dataset ids to the appropriate datasource info object so we can navigate any relative references\r\n *\r\n * @param objs Thes can be widgets, selectors, or urlParameters\r\n * @param datasourceInfos A list of objects that contain key details about the datasources from the application\r\n * @private\r\n */\r\nexport function _updateDatasourceReferences(\r\n objs: any,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n) {\r\n // objects can be events or widgets\r\n /* istanbul ignore else */\r\n if (objs && Array.isArray(objs)) {\r\n objs.forEach(obj => {\r\n if (Array.isArray(obj.datasets)) {\r\n obj.datasets.forEach((dataset: IDashboardDataset) => {\r\n // when the datasource has an itemId it's an external datasource\r\n const itemId: string = common.cleanLayerBasedItemId(\r\n common.getProp(dataset, \"dataSource.itemId\")\r\n );\r\n if (itemId) {\r\n const layerId: number = common.cleanLayerId(\r\n common.getProp(dataset, \"dataSource.layerId\")\r\n );\r\n datasourceInfos.some(ds => {\r\n if (ds.itemId === itemId && ds.layerId === layerId) {\r\n _updateReferences(ds, obj.id);\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n });\r\n } else {\r\n // add placeholder for map layer datasource info so we can know the items that reference them\r\n // needed when item field reference are derived from another widgets datasource eg. <dashboardWidgetId>#datasetname\r\n const id: any = common.getProp(dataset, \"dataSource.id\");\r\n if (id) {\r\n const dashboardLayerId: string = id.split(\"#\")[1];\r\n datasourceInfos.some(ds => {\r\n if (ds.ids.indexOf(dashboardLayerId) > -1) {\r\n _updateReferences(ds, obj.id);\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n });\r\n }\r\n }\r\n });\r\n }\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Templatize all datasets and/or events for the objects at the given path\r\n *\r\n * @param itemTemplate Template for the dashboard item\r\n * @param path A property path to an array of objects that could contain datasets or events\r\n * @param datasourceInfos A list of objects that contain key details about the datasources from the application\r\n * @private\r\n */\r\nexport function _templatize(\r\n itemTemplate: common.IItemTemplate,\r\n path: string,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n) {\r\n const obj: any[] = common.getProp(itemTemplate, path);\r\n /* istanbul ignore else */\r\n if (obj) {\r\n common.setProp(\r\n itemTemplate,\r\n path,\r\n _templatizeByDatasource(obj, datasourceInfos)\r\n );\r\n }\r\n}\r\n\r\n/**\r\n * For any service dataset datasource templatize all field references\r\n *\r\n * @param objs A list of objects that can contain field references\r\n * @param datasourceInfos A list of objects that contain key details about the datasources from the application\r\n * @returns An updated list of objects with templatized field references\r\n * @private\r\n */\r\nexport function _templatizeByDatasource(\r\n objs: any[],\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): any {\r\n if (Array.isArray(objs)) {\r\n return objs.map(obj => {\r\n let _obj: any = obj;\r\n if (Array.isArray(_obj.events)) {\r\n // Events can be associated with datasets but they can also be associated with a target\r\n // In some cases an event will have a source and a target.\r\n // Handle these specifically first to ensure that it has the correct layer reference\r\n _obj.events = _obj.events.map((event: any) => {\r\n const _event: any = event;\r\n /* istanbul ignore else */\r\n if (Array.isArray(_event.actions)) {\r\n _event.actions = _event.actions.map((action: any) => {\r\n const _action: any = action;\r\n if (\r\n _action.fieldMap &&\r\n _action.targetId &&\r\n _action.targetId.indexOf(\"#\") > -1\r\n ) {\r\n const datasourceInfo = _getDatasourceInfo(\r\n _action,\r\n datasourceInfos\r\n );\r\n /* istanbul ignore else */\r\n if (datasourceInfo) {\r\n const fields: any[] = common.getProp(\r\n datasourceInfo,\r\n \"fields\"\r\n );\r\n const basePath: string = common.getProp(\r\n datasourceInfo,\r\n \"basePath\"\r\n );\r\n /* istanbul ignore else */\r\n if (Array.isArray(fields) && basePath) {\r\n _action.fieldMap = _action.fieldMap.map((m: any) => {\r\n const _m: any = m;\r\n _m.targetName = common.templatizeFieldReferences(\r\n _m.targetName,\r\n fields,\r\n basePath\r\n );\r\n return _m;\r\n });\r\n }\r\n }\r\n }\r\n return _action;\r\n });\r\n }\r\n return _event;\r\n });\r\n }\r\n if (Array.isArray(_obj.datasets)) {\r\n _obj.datasets = _obj.datasets.map((dataset: any) => {\r\n let _dataset: any = dataset;\r\n if (_dataset.type === \"serviceDataset\") {\r\n const datasourceInfo = _getDatasourceInfo(dataset, datasourceInfos);\r\n /* istanbul ignore else */\r\n if (datasourceInfo) {\r\n const fields: any[] = common.getProp(datasourceInfo, \"fields\");\r\n const basePath: string = common.getProp(\r\n datasourceInfo,\r\n \"basePath\"\r\n );\r\n /* istanbul ignore else */\r\n if (Array.isArray(fields) && basePath) {\r\n _obj = common.templatizeFieldReferences(_obj, fields, basePath);\r\n _dataset = common.templatizeFieldReferences(\r\n _dataset,\r\n fields,\r\n basePath\r\n );\r\n }\r\n }\r\n }\r\n return _dataset;\r\n });\r\n return _obj;\r\n } else return _obj;\r\n });\r\n } else {\r\n return objs;\r\n }\r\n}\r\n\r\n/**\r\n * Find the appropriate datasource info object from the datasourceInfo collection\r\n *\r\n * @param obj Can be a Dataset or an event\r\n * @param datasourceInfos A list of objects that contain key details about the datasources from the application\r\n * @returns The supporting datasource info for the given object\r\n * @private\r\n */\r\nexport function _getDatasourceInfo(\r\n obj: any,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): any {\r\n let info: any;\r\n // the datasource will have an id property when it's referencing a map layer\r\n // the fields collection will already be defined\r\n const id: string =\r\n common.getProp(obj, \"dataSource.id\") || common.getProp(obj, \"targetId\");\r\n if (id) {\r\n const dashboardLayerId: string = id.split(\"#\")[1];\r\n if (\r\n !datasourceInfos.some(di => {\r\n info = di.ids.indexOf(dashboardLayerId) > -1 ? di : info;\r\n return di.ids.indexOf(dashboardLayerId) > -1;\r\n })\r\n ) {\r\n // in some cases the id will not contain a layer name...it will have the dashboard id for another widget\r\n // in that case lookup the datasource from referenced widget\r\n const dashboardWidgetId: string = id.split(\"#\")[0];\r\n datasourceInfos.some(di => {\r\n const references: string[] = di.references || [];\r\n const hasRef: boolean = references.indexOf(dashboardWidgetId) > -1;\r\n info = hasRef ? di : info;\r\n return hasRef;\r\n });\r\n }\r\n } else {\r\n // otherwise match the itemId and the layerId to get the correct fields and path\r\n const itemId: any = common.cleanLayerBasedItemId(\r\n common.getProp(obj, \"dataSource.itemId\")\r\n );\r\n const layerId: any = common.cleanLayerId(\r\n common.getProp(obj, \"dataSource.layerId\")\r\n );\r\n /* istanbul ignore else */\r\n if (itemId) {\r\n datasourceInfos.some(di => {\r\n const matches: boolean = itemId === di.itemId && layerId === di.layerId;\r\n info = matches ? di : info;\r\n return matches;\r\n });\r\n }\r\n }\r\n return info;\r\n}\r\n\r\n/**\r\n * Verifies if the datasource info contains the given id and adds it if not\r\n *\r\n * @param ds The datasource info to add the reference to\r\n * @param id The id from dashboard object, commonly another widget\r\n * @private\r\n */\r\nexport function _updateReferences(\r\n ds: common.IDatasourceInfo,\r\n id: string\r\n): void {\r\n ds.references = Array.isArray(ds.references) ? ds.references : [];\r\n if (ds.references.indexOf(id) < 0) {\r\n ds.references.push(id);\r\n }\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\nimport * as common from \"@esri/solution-common\";\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\n/**\r\n * Converts a web mapping application item into a template.\r\n *\r\n * @param itemInfo Info about the item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @returns A promise that will resolve when the template has been created\r\n */\r\nexport function convertItemToTemplate(\r\n itemTemplate: common.IItemTemplate,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n // Remove org base URL and app id, e.g.,\r\n // http://anOrg.maps.arcgis.com/apps/CrowdsourcePolling/index.html?appid=6fc5992522d34a6b5ce80d17835eea21\r\n // to\r\n // <placeholder(SERVER_NAME)>/apps/CrowdsourcePolling/index.html?appid={{<itemId>.id}}\r\n // Need to add placeholder server name because otherwise AGOL makes URL null\r\n let portalUrl: string = \"\";\r\n if (itemTemplate.item.url) {\r\n const templatizedUrl = itemTemplate.item.url;\r\n const iSep = templatizedUrl.indexOf(\"//\");\r\n itemTemplate.item.url =\r\n common.placeholder(common.SERVER_NAME) + // add placeholder server name\r\n templatizedUrl.substring(\r\n templatizedUrl.indexOf(\"/\", iSep + 2),\r\n templatizedUrl.lastIndexOf(\"=\") + 1\r\n ) +\r\n itemTemplate.item.id; // templatized id\r\n\r\n portalUrl = templatizedUrl.replace(\r\n templatizedUrl.substring(templatizedUrl.indexOf(\"/\", iSep + 2)),\r\n \"\"\r\n );\r\n }\r\n\r\n // Extract dependencies\r\n itemTemplate.dependencies = _extractDependencies(itemTemplate);\r\n\r\n // Set the folder\r\n common.setProp(itemTemplate, \"data.folderId\", \"{{folderId}}\");\r\n // Set the map or group after we've extracted them as dependencies\r\n _templatizeIdPaths(itemTemplate, [\r\n \"data.map.itemId\",\r\n \"data.map.appProxy.mapItemId\",\r\n \"data.values.webmap\",\r\n \"data.values.group\"\r\n ]);\r\n\r\n // force the appItemId to be pulled directly from the template item\r\n // this is to address solution.js #124\r\n _templatizeIdPath(itemTemplate, \"data.appItemId\", itemTemplate.itemId);\r\n\r\n setValues(\r\n itemTemplate,\r\n [\r\n \"data.logo\",\r\n \"data.map.portalUrl\",\r\n \"data.portalUrl\",\r\n \"data.httpProxy.url\"\r\n ],\r\n common.placeholder(common.SERVER_NAME)\r\n );\r\n\r\n common.setProp(\r\n itemTemplate,\r\n \"data.geometryService\",\r\n common.placeholder(common.GEOMETRY_SERVER_NAME)\r\n );\r\n\r\n templatizeDatasources(itemTemplate, srcAuthentication, portalUrl).then(\r\n () => {\r\n templatizeWidgets(\r\n itemTemplate,\r\n srcAuthentication,\r\n portalUrl,\r\n \"data.widgetPool.widgets\"\r\n ).then(\r\n _itemTemplate => {\r\n templatizeWidgets(\r\n _itemTemplate,\r\n srcAuthentication,\r\n portalUrl,\r\n \"data.widgetOnScreen.widgets\",\r\n true\r\n ).then(\r\n updatedItemTemplate => {\r\n templatizeValues(\r\n updatedItemTemplate,\r\n srcAuthentication,\r\n portalUrl,\r\n \"data.values\"\r\n ).then(\r\n _updatedItemTemplate => {\r\n resolve(_updatedItemTemplate);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n });\r\n}\r\n\r\nexport function templatizeDatasources(\r\n itemTemplate: common.IItemTemplate,\r\n authentication: common.UserSession,\r\n portalUrl: string\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n const dataSources: any = common.getProp(\r\n itemTemplate,\r\n \"data.dataSource.dataSources\"\r\n );\r\n if (dataSources && Object.keys(dataSources).length > 0) {\r\n const pendingRequests = new Array<Promise<void>>();\r\n Object.keys(dataSources).forEach(k => {\r\n const ds: any = dataSources[k];\r\n common.setProp(ds, \"portalUrl\", common.placeholder(common.SERVER_NAME));\r\n const itemId: any = common.getProp(ds, \"itemId\");\r\n if (common.getProp(ds, \"url\")) {\r\n if (itemId) {\r\n const layerId = ds.url.substr(\r\n (ds.url as string).lastIndexOf(\"/\") + 1\r\n );\r\n ds.itemId = common.templatizeTerm(\r\n itemId,\r\n itemId,\r\n \".layer\" + layerId + \".itemId\"\r\n );\r\n }\r\n const urlResults: any = findUrls(\r\n ds.url,\r\n portalUrl,\r\n [],\r\n [],\r\n authentication\r\n );\r\n pendingRequests.push(\r\n new Promise<void>((resolveReq, rejectReq) => {\r\n handleServiceRequests(\r\n urlResults.serviceRequests,\r\n urlResults.requestUrls,\r\n urlResults.testString\r\n ).then(\r\n response => {\r\n ds.url = response;\r\n resolveReq();\r\n },\r\n e => rejectReq(common.fail(e))\r\n );\r\n })\r\n );\r\n } else {\r\n if (itemId) {\r\n ds.itemId = common.templatizeTerm(itemId, itemId, \".itemId\");\r\n }\r\n }\r\n });\r\n Promise.all(pendingRequests).then(\r\n () => resolve(itemTemplate),\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve(itemTemplate);\r\n }\r\n });\r\n}\r\n\r\nexport function templatizeWidgets(\r\n itemTemplate: common.IItemTemplate,\r\n authentication: common.UserSession,\r\n portalUrl: string,\r\n widgetPath: string,\r\n isOnScreen = false\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n // update widgets\r\n const widgets: any[] = common.getProp(itemTemplate, widgetPath) || [];\r\n let serviceRequests: any[] = [];\r\n let requestUrls: string[] = [];\r\n\r\n widgets.forEach(widget => {\r\n /* istanbul ignore else */\r\n if (!isOnScreen && common.getProp(widget, \"icon\")) {\r\n setValues(widget, [\"icon\"], common.placeholder(common.SERVER_NAME));\r\n }\r\n const config: any = widget.config;\r\n if (config) {\r\n const sConfig: string = JSON.stringify(config);\r\n const urlResults: any = findUrls(\r\n sConfig,\r\n portalUrl,\r\n requestUrls,\r\n serviceRequests,\r\n authentication\r\n );\r\n\r\n widget.config = JSON.parse(urlResults.testString);\r\n serviceRequests = urlResults.serviceRequests;\r\n requestUrls = urlResults.requestUrls;\r\n }\r\n });\r\n\r\n if (serviceRequests.length > 0) {\r\n const sWidgets: string = JSON.stringify(widgets);\r\n handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(\r\n response => {\r\n common.setProp(itemTemplate, widgetPath, JSON.parse(response));\r\n resolve(itemTemplate);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve(itemTemplate);\r\n }\r\n });\r\n}\r\n\r\nexport function templatizeValues(\r\n itemTemplate: common.IItemTemplate,\r\n authentication: common.UserSession,\r\n portalUrl: string,\r\n widgetPath: string\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n // update properties of values collection for web app templates\r\n let values: any = common.getProp(itemTemplate, widgetPath);\r\n let serviceRequests: any[] = [];\r\n let requestUrls: string[] = [];\r\n\r\n if (values) {\r\n if (common.getProp(values, \"icon\")) {\r\n setValues(values, [\"icon\"], common.placeholder(common.SERVER_NAME));\r\n }\r\n\r\n const sConfig: string = JSON.stringify(values);\r\n const urlResults: any = findUrls(\r\n sConfig,\r\n portalUrl,\r\n requestUrls,\r\n serviceRequests,\r\n authentication\r\n );\r\n\r\n values = JSON.parse(urlResults.testString);\r\n serviceRequests = urlResults.serviceRequests;\r\n requestUrls = urlResults.requestUrls;\r\n }\r\n\r\n if (serviceRequests.length > 0) {\r\n const sWidgets: string = JSON.stringify(values);\r\n handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(\r\n response => {\r\n common.setProp(itemTemplate, widgetPath, JSON.parse(response));\r\n resolve(itemTemplate);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve(itemTemplate);\r\n }\r\n });\r\n}\r\n\r\nexport function handleServiceRequests(\r\n serviceRequests: any[],\r\n requestUrls: string[],\r\n objString: string\r\n): Promise<string> {\r\n return new Promise<string>((resolve, reject) => {\r\n if (serviceRequests && serviceRequests.length > 0) {\r\n let i: number = 0;\r\n Promise.all(serviceRequests).then(\r\n serviceResponses => {\r\n serviceResponses.forEach(serviceResponse => {\r\n if (common.getProp(serviceResponse, \"serviceItemId\")) {\r\n const serviceTemplate: string =\r\n \"{{\" +\r\n serviceResponse.serviceItemId +\r\n (serviceResponse.hasOwnProperty(\"id\")\r\n ? \".layer\" + serviceResponse.id\r\n : \"\") +\r\n \".url}}\";\r\n objString = replaceUrl(\r\n objString,\r\n requestUrls[i],\r\n serviceTemplate,\r\n true\r\n );\r\n }\r\n i++;\r\n });\r\n resolve(objString);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve(objString);\r\n }\r\n });\r\n}\r\n\r\nexport function findUrls(\r\n testString: string,\r\n portalUrl: string,\r\n requestUrls: string[],\r\n serviceRequests: any[],\r\n authentication: common.UserSession\r\n) {\r\n const options: any = {\r\n f: \"json\",\r\n authentication: authentication\r\n };\r\n // test for URLs\r\n const results = testString.match(/(\\bhttps?:\\/\\/[-A-Z0-9/._]*)/gim);\r\n if (results && results.length) {\r\n results.forEach((url: string) => {\r\n if (url.indexOf(\"NAServer\") > -1) {\r\n testString = replaceUrl(\r\n testString,\r\n url,\r\n common.placeholder(common.NA_SERVER_NAME)\r\n );\r\n } else if (url.indexOf(\"GeocodeServer\") > -1) {\r\n testString = replaceUrl(\r\n testString,\r\n url,\r\n common.placeholder(common.GEOCODE_SERVER_NAME)\r\n );\r\n } else if (portalUrl && url.indexOf(portalUrl) > -1) {\r\n testString = replaceUrl(\r\n testString,\r\n portalUrl,\r\n common.placeholder(common.SERVER_NAME)\r\n );\r\n } else if (url.indexOf(\"FeatureServer\") > -1) {\r\n if (requestUrls.indexOf(url) === -1) {\r\n requestUrls.push(url);\r\n serviceRequests.push(common.rest_request(url, options));\r\n }\r\n }\r\n });\r\n }\r\n return {\r\n testString,\r\n requestUrls,\r\n serviceRequests\r\n };\r\n}\r\n\r\n/**\r\n * Replace url with templatized url value\r\n *\r\n * @param obj can be a single url string or a stringified JSON object\r\n * @param url the current url we are testing for\r\n * @param newUrl the templatized url\r\n * @param validateFullUrl should only replace url when we have a full match.\r\n * This property is only relevant when the obj is a stringified JSON object.\r\n *\r\n * @returns the obj with any instances of the url replaced\r\n */\r\nexport function replaceUrl(\r\n obj: string,\r\n url: string,\r\n newUrl: string,\r\n validateFullUrl: boolean = false\r\n) {\r\n const enforceFullUrl: boolean = validateFullUrl && obj.indexOf('\"') > -1;\r\n const re = new RegExp(enforceFullUrl ? '\"' + url + '\"' : url, \"gmi\");\r\n return obj.replace(re, enforceFullUrl ? '\"' + newUrl + '\"' : newUrl);\r\n}\r\n\r\nexport function setValues(\r\n itemTemplate: common.IItemTemplate,\r\n paths: string[],\r\n base: string\r\n) {\r\n paths.forEach(path => {\r\n const url: string = common.getProp(itemTemplate, path);\r\n if (url) {\r\n const subString: string = url.substring(\r\n url.indexOf(\"/\", url.indexOf(\"//\") + 2)\r\n );\r\n common.setProp(\r\n itemTemplate,\r\n path,\r\n subString !== url ? base + subString : base\r\n );\r\n }\r\n });\r\n}\r\n\r\nexport function fineTuneCreatedItem(\r\n originalTemplate: common.IItemTemplate,\r\n newlyCreatedItem: common.IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: common.UserSession\r\n): Promise<void> {\r\n return new Promise<void>(resolve => {\r\n // If this is a Web AppBuilder application, we will create a Code Attachment for downloading\r\n if (\r\n common.hasAnyKeyword(originalTemplate, [\r\n \"WAB2D\",\r\n \"WAB3D\",\r\n \"Web AppBuilder\"\r\n ])\r\n ) {\r\n // Update item so properties like appItemId can now be set now that we know the new apps ID\r\n const updateOptions: common.IItemUpdate = {\r\n id: newlyCreatedItem.itemId,\r\n url: newlyCreatedItem.item.url,\r\n data: newlyCreatedItem.data\r\n };\r\n const updateDef = common.updateItem(\r\n updateOptions,\r\n destinationAuthentication\r\n );\r\n\r\n const itemInfo = {\r\n tags: originalTemplate.item.tags,\r\n title: originalTemplate.item.title,\r\n type: \"Code Attachment\",\r\n typeKeywords: [\"Code\", \"Javascript\", \"Web Mapping Application\"],\r\n relationshipType: \"WMA2Code\",\r\n originItemId: newlyCreatedItem.itemId,\r\n url:\r\n common.checkUrlPathTermination(\r\n common.replaceInTemplate(\r\n common.placeholder(common.SERVER_NAME),\r\n templateDictionary\r\n )\r\n ) +\r\n \"sharing/rest/content/items/\" +\r\n newlyCreatedItem.itemId +\r\n \"/package\"\r\n };\r\n\r\n const createItemWithDataDef = common.createItemWithData(\r\n itemInfo,\r\n {},\r\n destinationAuthentication,\r\n templateDictionary.folderId\r\n );\r\n\r\n Promise.all([updateDef, createItemWithDataDef]).then(\r\n () => resolve(null),\r\n () => resolve(null)\r\n );\r\n } else {\r\n // Otherwise, nothing extra needed\r\n resolve(null);\r\n }\r\n });\r\n}\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\n/**\r\n * Gets the ids of the dependencies of an AGOL webapp item.\r\n *\r\n * @param fullItem A webapp item whose dependencies are sought\r\n * @returns A promise that will resolve with list of dependent ids\r\n * @private\r\n */\r\nexport function _extractDependencies(model: any): string[] {\r\n let processor = _getGenericWebAppDependencies;\r\n\r\n /*\r\n if (common.hasTypeKeyword(model, \"Story Map\")) {\r\n processor = getStoryMapDependencies;\r\n }\r\n */\r\n\r\n if (common.hasAnyKeyword(model, [\"WAB2D\", \"WAB3D\", \"Web AppBuilder\"])) {\r\n processor = _getWABDependencies;\r\n }\r\n\r\n return processor(model);\r\n}\r\n\r\n/**\r\n * Generic Web App Dependencies\r\n *\r\n * @private\r\n */\r\nexport function _getGenericWebAppDependencies(model: any): any {\r\n const props = [\"data.values.webmap\", \"data.values.group\"];\r\n return common.getProps(model, props);\r\n}\r\n\r\n//???\r\nexport function _getWABDependencies(model: any): string[] {\r\n const deps = [] as string[];\r\n const v = common.getProp(model, \"data.map.itemId\");\r\n if (v) {\r\n deps.push(v);\r\n }\r\n const dataSources = common.getProp(model, \"data.dataSource.dataSources\");\r\n if (dataSources) {\r\n Object.keys(dataSources).forEach(k => {\r\n const ds: any = dataSources[k];\r\n if (ds.itemId) {\r\n deps.push(ds.itemId);\r\n }\r\n });\r\n }\r\n return deps;\r\n}\r\n\r\n/**\r\n * Templatizes id properties for the paths provided\r\n *\r\n * @param itemTemplate The solution item template\r\n * @param paths A list of property paths that contain ids\r\n * @private\r\n */\r\nexport function _templatizeIdPaths(\r\n itemTemplate: common.IItemTemplate,\r\n paths: string[]\r\n) {\r\n paths.forEach(path => {\r\n const id: any = common.getProp(itemTemplate, path);\r\n _templatizeIdPath(itemTemplate, path, id);\r\n });\r\n}\r\n\r\n/**\r\n * Templatizes id property for the path provided\r\n *\r\n * @param itemTemplate The solution item template\r\n * @param path A path to an id property\r\n * @param id The base id to use when templatizing\r\n * @private\r\n */\r\nexport function _templatizeIdPath(\r\n itemTemplate: common.IItemTemplate,\r\n path: string,\r\n id: string\r\n) {\r\n common.setProp(itemTemplate, path, common.templatizeTerm(id, id, \".itemId\"));\r\n}\r\n\r\n/**\r\n * Templatize field references for datasources and widgets.\r\n *\r\n * @param solutionTemplate The solution item template\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns The solutionTemplate with templatized field references\r\n */\r\nexport function postProcessFieldReferences(\r\n solutionTemplate: common.IItemTemplate,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): common.IItemTemplate {\r\n // handle datasources common for WAB apps\r\n const dataSources: any = common.getProp(\r\n solutionTemplate,\r\n \"data.dataSource.dataSources\"\r\n );\r\n if (dataSources && Object.keys(dataSources).length > 0) {\r\n Object.keys(dataSources).forEach(k => {\r\n const ds: any = dataSources[k];\r\n dataSources[k] = _templatizeObject(ds, datasourceInfos);\r\n });\r\n common.setProp(\r\n solutionTemplate,\r\n \"data.dataSource.dataSources\",\r\n dataSources\r\n );\r\n }\r\n\r\n // handle widgets common for WAB apps\r\n const paths: string[] = [\r\n \"data.widgetPool.widgets\",\r\n \"data.widgetOnScreen.widgets\"\r\n ];\r\n paths.forEach(path => {\r\n const widgets = common.getProp(solutionTemplate, path);\r\n if (widgets) {\r\n common.setProp(\r\n solutionTemplate,\r\n path,\r\n _templatizeObjectArray(widgets, datasourceInfos)\r\n );\r\n }\r\n });\r\n\r\n // handle values common for web app templates\r\n const values: any = common.getProp(solutionTemplate, \"data.values\");\r\n if (values) {\r\n common.setProp(\r\n solutionTemplate,\r\n \"data.values\",\r\n _templatizeObject(values, datasourceInfos)\r\n );\r\n }\r\n\r\n return solutionTemplate;\r\n}\r\n\r\n/**\r\n * Templatize field references for given dataSource from the web application.\r\n *\r\n * @param obj The dataSource or widget object from the web application.\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns The dataSource with templatized field references\r\n * @private\r\n */\r\nexport function _templatizeObject(\r\n obj: any,\r\n datasourceInfos: common.IDatasourceInfo[],\r\n templatizeKeys: boolean = false\r\n): any {\r\n obj = _prioritizedTests(obj, datasourceInfos, templatizeKeys);\r\n const replaceOrder: common.IDatasourceInfo[] = _getReplaceOrder(\r\n obj,\r\n datasourceInfos\r\n );\r\n replaceOrder.forEach(ds => {\r\n obj = common.templatizeFieldReferences(\r\n obj,\r\n ds.fields,\r\n ds.basePath,\r\n templatizeKeys\r\n );\r\n });\r\n return obj;\r\n}\r\n\r\n/**\r\n * Templatize field references from an array of various objects from the web application.\r\n *\r\n * @param objects A list of widgets or objects from the web application that may contain field references.\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns The widgets with templatized field references\r\n * @private\r\n */\r\nexport function _templatizeObjectArray(\r\n objects: any[],\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): any {\r\n const updateKeyObjects: string[] = [\"SmartEditor\", \"Screening\"];\r\n return objects.map(obj => {\r\n // only templatize the config and lower\r\n if (obj.config) {\r\n const templatizeKeys: boolean = updateKeyObjects.indexOf(obj.name) > -1;\r\n obj.config = _templatizeObject(\r\n obj.config,\r\n datasourceInfos,\r\n templatizeKeys\r\n );\r\n }\r\n return obj;\r\n });\r\n}\r\n\r\n/**\r\n * Gets an order for testing wit the various datasource info objects against the widget or dataSource.\r\n * A widget or dataSource that contain a layers url or webmap layer id are more likely\r\n * to have field references from that layer.\r\n *\r\n * @param obj The dataSource or widget object from the web application.\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns A list of datasourceInfo objects sorted based on the presence of a layers url or id\r\n * @private\r\n */\r\nexport function _getReplaceOrder(\r\n obj: any,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n) {\r\n const objString: string = JSON.stringify(obj);\r\n\r\n // If we don't find any layer url, web map layer id, service url, agol itemId then remove the datasource.\r\n const _datasourceInfos: common.IDatasourceInfo[] = datasourceInfos.filter(\r\n ds => _getSortOrder(ds, objString) < 4\r\n );\r\n return _datasourceInfos.sort((a, b) => {\r\n return _getSortOrder(a, objString) - _getSortOrder(b, objString);\r\n });\r\n}\r\n\r\n/**\r\n * Determine an order for checking field names against a dataSource or widget.\r\n * Sort order preference is set in this order: layer url, web map layer id, service url, agol itemId\r\n *\r\n * @param datasourceInfo The datasource object with key properties about the service.\r\n * @param testString A stringified version of a widget or dataSource\r\n * @returns The prioritized order for testing\r\n * @private\r\n */\r\nexport function _getSortOrder(\r\n datasourceInfo: common.IDatasourceInfo,\r\n testString: string\r\n): number {\r\n const url = datasourceInfo.url;\r\n const itemId = datasourceInfo.itemId;\r\n const layerId = datasourceInfo.layerId;\r\n\r\n // if we have the url and the layerID and its found prioritize it first\r\n // else if we find the maps layer id prioritze it first\r\n let layerUrlTest: any;\r\n if (url && !isNaN(layerId)) {\r\n layerUrlTest = new RegExp(\r\n url.replace(/[.]/, \".layer\" + layerId + \".\"),\r\n \"gm\"\r\n );\r\n }\r\n if (layerUrlTest && layerUrlTest.test(testString)) {\r\n return 1;\r\n } else if (datasourceInfo.ids.length > 0) {\r\n if (\r\n datasourceInfo.ids.some(id => {\r\n const layerMapIdTest: any = new RegExp(id, \"gm\");\r\n return layerMapIdTest.test(testString);\r\n })\r\n ) {\r\n return 1;\r\n }\r\n }\r\n\r\n // if neither full layer url or map layer id are found...check to see if we can\r\n // find the base service url\r\n if (url) {\r\n const serviceUrlTest: any = new RegExp(url, \"gm\");\r\n if (serviceUrlTest.test(testString)) {\r\n return 2;\r\n }\r\n }\r\n // if none of the above see if we can find an AGOL item id reference\r\n if (itemId) {\r\n const itemIdTest: any = new RegExp(itemId, \"gm\");\r\n if (itemIdTest.test(testString)) {\r\n return 3;\r\n }\r\n }\r\n return 4;\r\n}\r\n\r\n/**\r\n * These tests will run prior to the tests associated with the higher level tests based on sort order.\r\n * The tests work more like cloning an object where we go through and review each individual property.\r\n * If we find a url or webmap layer id we will templatize the parent object that contains this property.\r\n * Many widgets will store one of these two properties in an object that will also contain various field references.\r\n *\r\n * @param obj The dataSource or widget object from the application\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns An updated instance of the dataSource or widget with as many field references templatized as possible.\r\n * @private\r\n */\r\nexport function _prioritizedTests(\r\n obj: any,\r\n datasourceInfos: common.IDatasourceInfo[],\r\n templatizeKeys: boolean\r\n): any {\r\n const objString: string = JSON.stringify(obj);\r\n const hasDatasources = datasourceInfos.filter(ds => {\r\n let urlTest: any;\r\n if (ds.url && !isNaN(ds.layerId)) {\r\n urlTest = new RegExp(\r\n ds.url.replace(/[.]/, \".layer\" + ds.layerId + \".\"),\r\n \"gm\"\r\n );\r\n }\r\n\r\n let hasMapLayerId: boolean = false;\r\n if (ds.ids.length > 0) {\r\n hasMapLayerId = ds.ids.some(id => {\r\n const idTest: any = new RegExp(id, \"gm\");\r\n return idTest.test(objString);\r\n });\r\n }\r\n\r\n if (hasMapLayerId || (urlTest && urlTest.test(objString))) {\r\n return ds;\r\n }\r\n });\r\n if (hasDatasources.length > 0) {\r\n hasDatasources.forEach(ds => {\r\n // specific url reference is the most common\r\n obj = _templatizeParentByURL(obj, ds, templatizeKeys);\r\n if (ds.ids.length > 0) {\r\n // the second most common is to use the layerId from the webmap\r\n ds.ids.forEach(id => {\r\n obj = _templatizeParentByWebMapLayerId(obj, ds, id, templatizeKeys);\r\n });\r\n }\r\n });\r\n }\r\n return obj;\r\n}\r\n\r\n/**\r\n * This is very close to common.cloneObject but will test if an object\r\n * has one of the datasource urls as a property. If it finds one it will\r\n * templatize it's parent based on the fields from that datasource\r\n *\r\n * @param obj The dataSource or widget object from the application\r\n * @param ds A datasourceInfo object to use for testing against the current dataSource or widget\r\n * @returns The updated instance of the object with as many field references templatized as possible\r\n * @private\r\n */\r\nexport function _templatizeParentByURL(\r\n obj: { [index: string]: any },\r\n ds: common.IDatasourceInfo,\r\n templatizeKeys: boolean\r\n): any {\r\n let clone: { [index: string]: any } = {};\r\n const url = ds.url;\r\n const layerId = ds.layerId;\r\n\r\n let urlTest: any;\r\n if (url && !isNaN(layerId)) {\r\n urlTest = new RegExp(url.replace(/[.]/, \".layer\" + layerId + \".\"), \"gm\");\r\n }\r\n\r\n if (Array.isArray(obj)) {\r\n clone = obj.map(c => {\r\n return _templatizeParentByURL(c, ds, templatizeKeys);\r\n });\r\n } else if (typeof obj === \"object\") {\r\n for (const i in obj) {\r\n if (obj[i] != null && typeof obj[i] === \"object\") {\r\n clone[i] = _templatizeParentByURL(obj[i], ds, templatizeKeys);\r\n } else {\r\n if (urlTest && urlTest.test(obj[i])) {\r\n obj = common.templatizeFieldReferences(\r\n obj,\r\n ds.fields,\r\n ds.basePath,\r\n templatizeKeys\r\n );\r\n }\r\n clone[i] = obj[i];\r\n }\r\n }\r\n } else {\r\n clone = obj;\r\n }\r\n return clone;\r\n}\r\n\r\n/**\r\n * This is very close to common.cloneObject but will test if an object\r\n * has one of the datasource webmap layer ids as a property. If it finds one it will\r\n * templatize it's parent based on the fields from that datasource.\r\n *\r\n * @param obj The dataSource or widget object from the application\r\n * @param ds A datasourceInfo object to use for testing against the current dataSource or widget\r\n * @param id A webmap layer id to test with.\r\n * @returns The updated instance of the object with as many field references templatized as possible\r\n * @private\r\n */\r\nexport function _templatizeParentByWebMapLayerId(\r\n obj: { [index: string]: any },\r\n ds: common.IDatasourceInfo,\r\n id: string,\r\n templatizeKeys: boolean\r\n): any {\r\n let clone: { [index: string]: any } = {};\r\n const idTest: any = new RegExp(id, \"gm\");\r\n if (Array.isArray(obj)) {\r\n clone = obj.map(c => {\r\n return _templatizeParentByWebMapLayerId(c, ds, id, templatizeKeys);\r\n });\r\n } else if (typeof obj === \"object\") {\r\n for (const i in obj) {\r\n if (obj[i] !== null) {\r\n // In some web application templates they store a stringified version of an object that can\r\n // contain multiple layer references at a very high level on the main values collection.\r\n // This was causing many other more typical layer references to be set incorrectly as the first\r\n // layerId found in this high level string would be used against the main object.\r\n let parsedProp: any;\r\n try {\r\n parsedProp = JSON.parse(obj[i]);\r\n } catch (error) {\r\n parsedProp = undefined;\r\n }\r\n if (parsedProp && typeof parsedProp === \"object\") {\r\n clone[i] = JSON.stringify(\r\n _templatizeParentByWebMapLayerId(parsedProp, ds, id, templatizeKeys)\r\n );\r\n } else if (typeof obj[i] === \"object\") {\r\n // some widgets store the layerId as a key to a collection of details that contain field references\r\n if (idTest.test(i) && templatizeKeys) {\r\n obj[i] = common.templatizeFieldReferences(\r\n obj[i],\r\n ds.fields,\r\n ds.basePath,\r\n templatizeKeys\r\n );\r\n }\r\n clone[i] = _templatizeParentByWebMapLayerId(\r\n obj[i],\r\n ds,\r\n id,\r\n templatizeKeys\r\n );\r\n } else {\r\n if (idTest.test(obj[i])) {\r\n obj = common.templatizeFieldReferences(\r\n obj,\r\n ds.fields,\r\n ds.basePath,\r\n templatizeKeys\r\n );\r\n }\r\n clone[i] = obj[i];\r\n }\r\n } else {\r\n clone[i] = obj[i];\r\n }\r\n }\r\n } else {\r\n clone = obj;\r\n }\r\n return clone;\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 * as common from \"@esri/solution-common\";\r\nimport * as notebook from \"../notebook\";\r\nimport * as webmappingapplication from \"../webmappingapplication\";\r\nimport * as workforce from \"../workforce\";\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 // Interrupt process if progress callback returns `false`\r\n if (\r\n !itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Started,\r\n 0\r\n )\r\n ) {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Ignored,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type));\r\n } else {\r\n // Replace the templatized symbols in a copy of the template\r\n let newItemTemplate: common.IItemTemplate = common.cloneObject(template);\r\n newItemTemplate = common.replaceInTemplate(\r\n newItemTemplate,\r\n templateDictionary\r\n );\r\n\r\n // Create the item, then update its URL with its new id\r\n\r\n // some fieldnames are used as keys for objects\r\n // when we templatize field references for web applications we first stringify the components of the\r\n // web application that could contain field references and then serach for them with a regular expression.\r\n // We also need to stringify the web application when de-templatizing so it will find all of these occurrences as well.\r\n if (template.type === \"Web Mapping Application\" && template.data) {\r\n newItemTemplate = JSON.parse(\r\n common.replaceInTemplate(\r\n JSON.stringify(newItemTemplate),\r\n templateDictionary\r\n )\r\n );\r\n }\r\n\r\n if (template.item.thumbnail) {\r\n newItemTemplate.item.thumbnail = template.item.thumbnail; // make sure that our File is still there\r\n }\r\n\r\n common\r\n .createItemWithData(\r\n newItemTemplate.item,\r\n newItemTemplate.data,\r\n destinationAuthentication,\r\n templateDictionary.folderId\r\n )\r\n .then(\r\n createResponse => {\r\n // Interrupt process if progress callback returns `false`\r\n if (\r\n !itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Created,\r\n template.estimatedDeploymentCostFactor / 2,\r\n createResponse.id\r\n )\r\n ) {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Cancelled,\r\n 0\r\n );\r\n common\r\n .removeItem(createResponse.id, destinationAuthentication)\r\n .then(\r\n () =>\r\n resolve(\r\n common.generateEmptyCreationResponse(template.type)\r\n ),\r\n () =>\r\n resolve(common.generateEmptyCreationResponse(template.type))\r\n );\r\n } else {\r\n // Add the new item to the settings\r\n templateDictionary[template.itemId] = {\r\n itemId: createResponse.id\r\n };\r\n newItemTemplate.itemId = createResponse.id;\r\n\r\n // Set the appItemId manually to get around cases where the path was incorrectly set\r\n // in legacy deployments\r\n if (\r\n newItemTemplate.type === \"Web Mapping Application\" &&\r\n template.data\r\n ) {\r\n common.setProp(\r\n newItemTemplate,\r\n \"data.appItemId\",\r\n createResponse.id\r\n );\r\n }\r\n const postProcess: boolean = common.hasUnresolvedVariables(\r\n newItemTemplate.data\r\n );\r\n\r\n // Update the template again now that we have the new item id\r\n const originalURL = newItemTemplate.item.url;\r\n newItemTemplate = common.replaceInTemplate(\r\n newItemTemplate,\r\n templateDictionary\r\n );\r\n\r\n // Update relationships\r\n let relationshipsDef = Promise.resolve(\r\n [] as common.IStatusResponse[]\r\n );\r\n if (newItemTemplate.relatedItems) {\r\n // Templatize references in relationships obj\r\n const updatedRelatedItems = common.replaceInTemplate(\r\n common.templatizeIds(newItemTemplate.relatedItems),\r\n templateDictionary\r\n ) as common.IRelatedItems[];\r\n\r\n // Add the relationships\r\n relationshipsDef = common.addForwardItemRelationships(\r\n newItemTemplate.itemId,\r\n updatedRelatedItems,\r\n destinationAuthentication\r\n );\r\n }\r\n\r\n // Check for extra processing for web mapping application et al.\r\n let customProcDef: Promise<void>;\r\n if (\r\n template.type === \"Web Mapping Application\" &&\r\n template.data &&\r\n common.hasAnyKeyword(template, [\r\n \"WAB2D\",\r\n \"WAB3D\",\r\n \"Web AppBuilder\"\r\n ])\r\n ) {\r\n // If this is a Web AppBuilder application, we will create a Code Attachment for downloading\r\n customProcDef = webmappingapplication.fineTuneCreatedItem(\r\n template,\r\n newItemTemplate,\r\n templateDictionary,\r\n destinationAuthentication\r\n );\r\n } else if (template.type === \"Workforce Project\") {\r\n customProcDef = workforce.fineTuneCreatedItem(\r\n newItemTemplate,\r\n destinationAuthentication,\r\n templateDictionary\r\n );\r\n } else if (template.type === \"Notebook\") {\r\n customProcDef = notebook.fineTuneCreatedItem(\r\n template,\r\n newItemTemplate,\r\n templateDictionary,\r\n destinationAuthentication\r\n );\r\n } else if (originalURL !== newItemTemplate.item.url) {\r\n // For web mapping applications that are not Web AppBuilder apps\r\n customProcDef = new Promise<void>((resolve2, reject2) => {\r\n common\r\n .updateItemURL(\r\n createResponse.id,\r\n newItemTemplate.item.url,\r\n destinationAuthentication\r\n )\r\n .then(() => resolve2(), reject2);\r\n });\r\n } else {\r\n customProcDef = Promise.resolve(null);\r\n }\r\n\r\n Promise.all([relationshipsDef, customProcDef]).then(\r\n () => {\r\n // Interrupt process if progress callback returns `false`\r\n if (\r\n !itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Finished,\r\n template.estimatedDeploymentCostFactor / 2,\r\n createResponse.id\r\n )\r\n ) {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Cancelled,\r\n 0\r\n );\r\n common\r\n .removeItem(createResponse.id, destinationAuthentication)\r\n .then(\r\n () =>\r\n resolve(\r\n common.generateEmptyCreationResponse(template.type)\r\n ),\r\n () =>\r\n resolve(\r\n common.generateEmptyCreationResponse(template.type)\r\n )\r\n );\r\n } else {\r\n resolve({\r\n item: newItemTemplate,\r\n id: createResponse.id,\r\n type: newItemTemplate.type,\r\n postProcess: postProcess\r\n });\r\n }\r\n },\r\n () => {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Failed,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type)); // fails to deploy all resources to the item\r\n }\r\n );\r\n }\r\n },\r\n () => {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Failed,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type)); // fails to create item\r\n }\r\n );\r\n }\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 * as common from \"@esri/solution-common\";\r\n\r\n/**\r\n * Converts an workforce item to a template.\r\n *\r\n * @param itemTemplate template for the workforce project item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @returns templatized itemTemplate\r\n */\r\nexport function convertItemToTemplate(\r\n itemTemplate: common.IItemTemplate,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession\r\n): Promise<common.IItemTemplate> {\r\n return common.convertWorkforceItemToTemplate(itemTemplate, srcAuthentication);\r\n}\r\n\r\n/**\r\n * Gets the current user and updates the dispatchers service\r\n *\r\n * @param newlyCreatedItem Item to be created; n.b.: this item is modified\r\n * @param destinationAuthentication The session used to create the new item(s)\r\n * @returns A promise that will resolve with { \"success\" === true || false }\r\n */\r\nexport function fineTuneCreatedItem(\r\n newlyCreatedItem: common.IItemTemplate,\r\n destinationAuthentication: common.UserSession,\r\n templateDictionary: any\r\n): Promise<any> {\r\n return common.fineTuneCreatedWorkforceItem(\r\n newlyCreatedItem,\r\n destinationAuthentication,\r\n \"\",\r\n templateDictionary\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 {\r\n UserSession,\r\n IItemUpdate,\r\n jsonToBlob,\r\n updateItem\r\n} from \"@esri/solution-common\";\r\n\r\nexport function updateNotebookData(\r\n itemId: string,\r\n data: any,\r\n authentication: UserSession\r\n): Promise<any> {\r\n const updateOptions: IItemUpdate = {\r\n id: itemId,\r\n data: jsonToBlob(data)\r\n };\r\n return updateItem(updateOptions, authentication);\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\nimport * as common from \"@esri/solution-common\";\r\n// Need to import collectively to enable spying\r\nimport * as notebookHelpers from \"./helpers/notebook-helpers\";\r\n\r\n/**\r\n * Converts a notebook item into a template.\r\n *\r\n * @param solutionItemId The solution to contain the template\r\n * @param itemInfo Info about the item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements\r\n * @returns A promise that will resolve when the template has been created\r\n */\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession,\r\n templateDictionary: any\r\n): Promise<common.IItemTemplate> {\r\n // Delegate back to simple-types, which will in-turn delegate\r\n // to convertNotebookToTemplate at the correct point in the process\r\n // This is a temporary refactor step\r\n return notebookHelpers.convertItemToTemplate(\r\n solutionItemId,\r\n itemInfo,\r\n destAuthentication,\r\n srcAuthentication,\r\n templateDictionary\r\n );\r\n}\r\n\r\n// Delegate back to simple-types\r\n// This is a temporary refactor step\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 notebookHelpers.createItemFromTemplate(\r\n template,\r\n templateDictionary,\r\n destinationAuthentication,\r\n itemProgressCallback\r\n );\r\n}\r\n\r\n/**\r\n * Converts a Python Notebook item to a template.\r\n *\r\n * @param itemTemplate template for the Python Notebook\r\n * @returns templatized itemTemplate\r\n */\r\nexport function convertNotebookToTemplate(\r\n itemTemplate: common.IItemTemplate\r\n): common.IItemTemplate {\r\n // The templates data to process\r\n const data: any = itemTemplate.data;\r\n deleteProps(data);\r\n let dataString: string = JSON.stringify(data);\r\n\r\n const idTest: RegExp = /[0-9A-F]{32}/gim;\r\n\r\n if (data && idTest.test(dataString)) {\r\n const ids: string[] = dataString.match(idTest) as string[];\r\n const verifiedIds: string[] = [];\r\n ids.forEach(id => {\r\n if (verifiedIds.indexOf(id) === -1) {\r\n verifiedIds.push(id);\r\n\r\n // templatize the itemId--but only once per unique id\r\n const regEx = new RegExp(id, \"gm\");\r\n dataString = dataString.replace(regEx, \"{{\" + id + \".itemId}}\");\r\n\r\n // update the dependencies\r\n if (itemTemplate.dependencies.indexOf(id) === -1) {\r\n itemTemplate.dependencies.push(id);\r\n }\r\n }\r\n });\r\n itemTemplate.data = JSON.parse(dataString);\r\n }\r\n\r\n return itemTemplate;\r\n}\r\n\r\n/**\r\n * Remove interpreter and papermill props\r\n * \r\n * This function will update the data passed in by removing key props\r\n *\r\n * @param data The notebooks data object\r\n *\r\n */\r\nexport function deleteProps(\r\n data:any\r\n): void {\r\n /* istanbul ignore else */\r\n if (data) {\r\n const props: string[] = [\"metadata.interpreter\", \"metadata.papermill\"];\r\n common.deleteProps(data, props);\r\n (data.cells || []).forEach((cell: any) => {\r\n common.deleteProps(cell, props);\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Update the notebooks data\r\n *\r\n * @param originalTemplate The original template item\r\n * @param newlyCreatedItem The current item that may have unswapped variables\r\n * @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies\r\n * @param authentication Credentials for the requests to the destination\r\n *\r\n * @returns A promise that will resolve once any updates have been made\r\n */\r\nexport function fineTuneCreatedItem(\r\n originalTemplate: common.IItemTemplate,\r\n newlyCreatedItem: common.IItemTemplate,\r\n templateDictionary: any,\r\n authentication: common.UserSession\r\n): Promise<void> {\r\n return new Promise<void>((resolve, reject) => {\r\n const updateOptions: common.IItemUpdate = {\r\n id: newlyCreatedItem.itemId,\r\n url: newlyCreatedItem.item.url,\r\n data: common.jsonToFile(\r\n newlyCreatedItem.data,\r\n newlyCreatedItem.itemId + \".ipynb\"\r\n )\r\n };\r\n common\r\n .updateItem(updateOptions, authentication)\r\n .then(() => resolve(null), reject);\r\n });\r\n}\r\n\r\n/**\r\n * Notebook specific post-processing actions\r\n *\r\n * @param {string} itemId The item ID\r\n * @param {string} type The template type\r\n * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} authentication The destination session info\r\n * @returns {Promise<any>}\r\n */\r\nexport function postProcess(\r\n itemId: string,\r\n type: string,\r\n itemInfos: any[],\r\n template: common.IItemTemplate,\r\n templates: common.IItemTemplate[],\r\n templateDictionary: any,\r\n authentication: common.UserSession\r\n): Promise<any> {\r\n return common.updateItemTemplateFromDictionary(\r\n itemId,\r\n templateDictionary,\r\n authentication\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 * as common from \"@esri/solution-common\";\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\n/**\r\n * Converts an AGOL OIC (Oriented Imagery Catalog) item to a template.\r\n *\r\n * @param itemTemplate Template for the OIC (Oriented Imagery Catalog) item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @returns Template for the solution item that contains key details for item reconstruction\r\n */\r\nexport function convertItemToTemplate(\r\n itemTemplate: common.IItemTemplate,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n // Extract dependencies\r\n _extractDependencies(itemTemplate, srcAuthentication).then(\r\n (results: any) => {\r\n itemTemplate.dependencies = results.dependencies;\r\n\r\n // Templatize the map layer ids after we've extracted them as dependencies\r\n /* istanbul ignore else */\r\n if (itemTemplate.data?.properties) {\r\n itemTemplate.data.properties.ServiceURL = _templatizeOicLayerUrl(\r\n itemTemplate.data.properties.ServiceURL,\r\n results.urlHash\r\n );\r\n itemTemplate.data.properties.OverviewURL = _templatizeOicLayerUrl(\r\n itemTemplate.data.properties.OverviewURL,\r\n results.urlHash\r\n );\r\n }\r\n\r\n resolve(itemTemplate);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n });\r\n}\r\n\r\n/**\r\n * Gets the ids of the dependencies of an AGOL OIC (Oriented Imagery Catalog) item.\r\n *\r\n * @param itemTemplate A OIC (Oriented Imagery Catalog) item whose dependencies are sought\r\n * @param authentication Credentials for any requests\r\n * @returns List of dependencies ids and url/itemId hash\r\n * @private\r\n */\r\nexport function _extractDependencies(\r\n itemTemplate: common.IItemTemplate,\r\n authentication: common.UserSession\r\n): Promise<any> {\r\n return new Promise<any>((resolve, reject) => {\r\n const dependencies: string[] = [];\r\n if (itemTemplate.data?.properties) {\r\n const layerURLs = [];\r\n /* istanbul ignore else */\r\n if (itemTemplate.data.properties.ServiceURL) {\r\n layerURLs.push(itemTemplate.data.properties.ServiceURL);\r\n }\r\n /* istanbul ignore else */\r\n if (\r\n itemTemplate.data.properties.OverviewURL &&\r\n itemTemplate.data.properties.OverviewURL !==\r\n itemTemplate.data.properties.ServiceURL\r\n ) {\r\n layerURLs.push(itemTemplate.data.properties.OverviewURL);\r\n }\r\n _getLayerIds(layerURLs, dependencies, authentication).then(\r\n results => {\r\n resolve(results);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve({\r\n dependencies: dependencies,\r\n urlHash: {}\r\n });\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Extracts the AGOL itemId for each layer in a list using the url.\r\n *\r\n * @param layerURLs List of OIC layer URLs\r\n * @param dependencies Current list of dependencies\r\n * @param authentication Credentials for any requests\r\n * @returns List of dependencies ids and url/itemId hash\r\n * @private\r\n */\r\nexport function _getLayerIds(\r\n layerURLs: string[],\r\n dependencies: string[],\r\n authentication: common.UserSession\r\n): Promise<any> {\r\n return new Promise<any>((resolve, reject) => {\r\n const urlHash: any = {};\r\n\r\n const options: any = {\r\n f: \"json\",\r\n authentication: authentication\r\n };\r\n const layerPromises: Array<Promise<any>> = [];\r\n const layerChecks: any = {};\r\n const filteredLayerURLs: any[] = layerURLs.filter(layerURL => {\r\n if (layerURL) {\r\n const results: any = /.+FeatureServer/g.exec(layerURL);\r\n const baseUrl: string =\r\n Array.isArray(results) && results.length > 0 ? results[0] : undefined;\r\n if (baseUrl) {\r\n // avoid redundant checks when we have a layer with subLayers\r\n /* istanbul ignore else */\r\n if (Object.keys(layerChecks).indexOf(baseUrl) < 0) {\r\n layerChecks[baseUrl] = common.rest_request(layerURL, options);\r\n }\r\n layerPromises.push(layerChecks[baseUrl]);\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n } else {\r\n return false;\r\n }\r\n });\r\n\r\n if (layerPromises.length > 0) {\r\n Promise.all(layerPromises).then(\r\n serviceResponses => {\r\n serviceResponses.forEach((serviceResponse, i) => {\r\n /* istanbul ignore else */\r\n if (common.getProp(serviceResponse, \"serviceItemId\")) {\r\n const id: string = serviceResponse.serviceItemId;\r\n /* istanbul ignore else */\r\n if (dependencies.indexOf(id) < 0) {\r\n dependencies.push(id);\r\n }\r\n urlHash[filteredLayerURLs[i]] = id;\r\n }\r\n });\r\n resolve({\r\n dependencies: dependencies,\r\n urlHash: urlHash\r\n });\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve({\r\n dependencies: dependencies,\r\n urlHash: urlHash\r\n });\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Templatizes the url and item id for a layer.\r\n *\r\n * @param layerURL OIC layer URL\r\n * @param urlHash Lookup object for analysis layers\r\n * @returns Templatized URL if layerURL is in the urlHash\r\n * @private\r\n */\r\nexport function _templatizeOicLayerUrl(layerURL: string, urlHash: any): string {\r\n let templatizedURL = layerURL;\r\n if (layerURL) {\r\n const id: any = urlHash[layerURL];\r\n if (id) {\r\n const layerId = layerURL.substr(layerURL.lastIndexOf(\"/\") + 1);\r\n templatizedURL = common.templatizeTerm(\r\n id,\r\n id,\r\n \".layer\" + layerId + \".url\"\r\n );\r\n }\r\n \r\n // replace everything up until /home with portalBaseUrl var and templatize the itemId\r\n templatizedURL = common.templatizeIds(\r\n templatizedURL.replace(/.+?(?=\\/home)/, \"{{portalBaseUrl}}\")\r\n );\r\n }\r\n return templatizedURL;\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 * as common from \"@esri/solution-common\";\r\nimport * as quickcaptureHelpers from \"./helpers/quickcapture-helpers\";\r\n\r\n//#region Publish Process ---------------------------------------------------------------------------------------//\r\n\r\n/**\r\n * Converts a Quick Capture item into a template.\r\n *\r\n * @param solutionItemId The solution to contain the template\r\n * @param itemInfo Info about the item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements\r\n * @returns A promise that will resolve when the template has been created\r\n */\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession,\r\n templateDictionary: any\r\n): Promise<common.IItemTemplate> {\r\n // Delegate back to simple-types, which will in-turn delegate\r\n // to convertNotebookToTemplate at the correct point in the process\r\n // This is a temporary refactor step\r\n return quickcaptureHelpers.convertItemToTemplate(\r\n solutionItemId,\r\n itemInfo,\r\n destAuthentication,\r\n srcAuthentication,\r\n templateDictionary\r\n );\r\n}\r\n\r\n/**\r\n * Converts an quick capture item to a template.\r\n *\r\n * @param itemTemplate template for the quick capture project item\r\n * @returns templatized itemTemplate\r\n */\r\nexport function convertQuickCaptureToTemplate(\r\n itemTemplate: common.IItemTemplate\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n // The templates data to process\r\n const data: any = itemTemplate.data;\r\n if (data && Array.isArray(data)) {\r\n let applicationRequest: Promise<any> = Promise.resolve(null);\r\n let applicationName: string = \"\";\r\n data.some((item: File) => {\r\n if (item.type === \"application/json\") {\r\n applicationName = item.name;\r\n applicationRequest = common.getBlobText(item);\r\n return true;\r\n }\r\n });\r\n\r\n applicationRequest.then(result => {\r\n // replace the template data array with the templatized application JSON\r\n itemTemplate.data = result\r\n ? {\r\n application: _templatizeApplication(\r\n JSON.parse(result),\r\n itemTemplate\r\n ),\r\n name: applicationName\r\n }\r\n : {};\r\n resolve(itemTemplate);\r\n }, reject);\r\n } else {\r\n resolve(itemTemplate);\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Templatizes key properties for a quick capture project and gathers item dependencies\r\n *\r\n * @param data the projects json\r\n * @param itemTemplate template for the quick capture project item\r\n * @returns templatized itemTemplate\r\n * @private\r\n */\r\nexport function _templatizeApplication(\r\n data: any,\r\n itemTemplate: common.IItemTemplate\r\n): any {\r\n // Quick Project item id\r\n _templatizeId(data, \"itemId\");\r\n\r\n // Set the admin email\r\n _templatizeAdminEmail(data);\r\n\r\n // datasource item id and url\r\n const dataSources: common.IQuickCaptureDatasource[] = data.dataSources;\r\n if (dataSources && Array.isArray(dataSources)) {\r\n dataSources.forEach(ds => {\r\n const id: string = ds.featureServiceItemId;\r\n if (id) {\r\n _updateDependencies(id, itemTemplate);\r\n _templatizeUrl(ds, \"featureServiceItemId\", \"url\");\r\n _templatizeId(ds, \"featureServiceItemId\");\r\n }\r\n });\r\n }\r\n return data;\r\n}\r\n\r\n/**\r\n * Templatize the email property\r\n *\r\n * @param data the quick capture application\r\n * @private\r\n */\r\nexport function _templatizeAdminEmail(data: any): void {\r\n if (common.getProp(data, \"preferences.adminEmail\")) {\r\n common.setProp(data, \"preferences.adminEmail\", \"{{user.email}}\");\r\n }\r\n}\r\n\r\n/**\r\n * Updates the templates dependencies list with unique item ids\r\n *\r\n * @param id the item id of the dependency\r\n * @param itemTemplate template for the quick capture project item\r\n * @returns templatized itemTemplate\r\n */\r\nexport function _updateDependencies(\r\n id: string,\r\n itemTemplate: common.IItemTemplate\r\n): void {\r\n if (itemTemplate.dependencies.indexOf(id) === -1) {\r\n itemTemplate.dependencies.push(id);\r\n }\r\n}\r\n\r\n/**\r\n * Templatize a url property\r\n *\r\n * @param obj the datasource object\r\n * @param idPath the path to the id property\r\n * @param urlPath the path to the url property\r\n * @private\r\n */\r\nexport function _templatizeUrl(\r\n obj: any,\r\n idPath: string,\r\n urlPath: string\r\n): void {\r\n const id: any = common.getProp(obj, idPath);\r\n const url: string = common.getProp(obj, urlPath);\r\n if (url) {\r\n const layerId = url.substr(url.lastIndexOf(\"/\") + 1);\r\n common.setProp(\r\n obj,\r\n urlPath,\r\n common.templatizeTerm(id, id, \".layer\" + layerId + \".url\")\r\n );\r\n }\r\n}\r\n\r\n/**\r\n * Templatize the item id property\r\n *\r\n * @param obj the datasource or object that contains the item id property\r\n * @param path the path to the id property\r\n * @private\r\n */\r\nexport function _templatizeId(obj: any, path: string): void {\r\n const id: any = common.getProp(obj, path);\r\n if (id) {\r\n common.setProp(obj, path, common.templatizeTerm(id, id, \".itemId\"));\r\n }\r\n}\r\n\r\n//#endregion\r\n\r\n//#region Deploy Process ---------------------------------------------------------------------------------------//\r\n\r\n// Delegate back to simple-types\r\n// This is a temporary refactor step\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 quickcaptureHelpers.createItemFromTemplate(\r\n template,\r\n templateDictionary,\r\n destinationAuthentication,\r\n itemProgressCallback\r\n );\r\n}\r\n\r\n/**\r\n * QuickCapture post-processing actions\r\n *\r\n * @param {string} itemId The item ID\r\n * @param {string} type The template type\r\n * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} authentication The destination session info\r\n * @returns Promise resolving to successfulness of update\r\n */\r\nexport function postProcess(\r\n itemId: string,\r\n type: string,\r\n itemInfos: any[],\r\n template: common.IItemTemplate,\r\n templates: common.IItemTemplate[],\r\n templateDictionary: any,\r\n authentication: common.UserSession\r\n): Promise<any> {\r\n return new Promise<any>((resolve, reject) => {\r\n template.data = common.replaceInTemplate(template.data, templateDictionary);\r\n common\r\n .updateItemTemplateFromDictionary(\r\n itemId,\r\n templateDictionary,\r\n authentication\r\n )\r\n .then(() => {\r\n common\r\n .updateItemResourceText(\r\n itemId,\r\n template.data.name,\r\n JSON.stringify(template.data.application),\r\n authentication\r\n )\r\n .then(resolve, reject);\r\n }, reject);\r\n });\r\n}\r\n\r\n//#endregion\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 * as common from \"@esri/solution-common\";\r\n\r\n/**\r\n * The portion of a Webmap URL between the server and the map id.\r\n *\r\n * @private\r\n */\r\nconst WEBMAP_APP_URL_PART: string = \"home/webmap/viewer.html?webmap=\";\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\n/**\r\n * Converts an AGOL webmap item to a template.\r\n *\r\n * @param itemTemplate Template for the webmap item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @returns Template for the solution item that contains key details for item reconstruction\r\n */\r\nexport function convertItemToTemplate(\r\n itemTemplate: common.IItemTemplate,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n // Templatize the app URL\r\n itemTemplate.item.url = itemTemplate.item.url ?\r\n common.checkUrlPathTermination(common.placeholder(common.SERVER_NAME)) +\r\n WEBMAP_APP_URL_PART +\r\n itemTemplate.item.id : itemTemplate.item.url; // templatized id\r\n\r\n // Extract dependencies\r\n _extractDependencies(itemTemplate, srcAuthentication).then(\r\n (results: any) => {\r\n itemTemplate.dependencies = results.dependencies;\r\n\r\n // Templatize the map layer ids after we've extracted them as dependencies\r\n if (itemTemplate.data) {\r\n _templatizeWebmapLayerIdsAndUrls(\r\n itemTemplate.data.operationalLayers,\r\n results.urlHash\r\n );\r\n _templatizeWebmapLayerIdsAndUrls(\r\n itemTemplate.data.tables,\r\n results.urlHash\r\n );\r\n\r\n // Exclude intialState\r\n _excludeInitialState(itemTemplate.data);\r\n }\r\n\r\n resolve(itemTemplate);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n });\r\n}\r\n\r\n/**\r\n * Gets the ids of the dependencies of an AGOL webmap item.\r\n *\r\n * @param itemTemplate A webmap item whose dependencies are sought\r\n * @param authentication Credentials for any requests\r\n * @returns List of dependencies ids and url/itemId hash\r\n * @private\r\n */\r\nexport function _extractDependencies(\r\n itemTemplate: common.IItemTemplate,\r\n authentication: common.UserSession\r\n): Promise<any> {\r\n return new Promise<any>((resolve, reject) => {\r\n const dependencies: string[] = [];\r\n if (itemTemplate.data) {\r\n const layers: any[] = itemTemplate.data.operationalLayers || [];\r\n const tables: any[] = itemTemplate.data.tables || [];\r\n const layersAndTables: any[] = layers.concat(tables);\r\n _getLayerIds(layersAndTables, dependencies, authentication).then(\r\n results => {\r\n resolve(results);\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve({\r\n dependencies: dependencies,\r\n urlHash: {}\r\n });\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Remove the initialState prop from webmaps saved from the new map viewer.\r\n * This allows the map to use the item extent property that we templatize.\r\n *\r\n * Added for issue #662\r\n *\r\n * @param data the data for the web maps item template\r\n * @returns void\r\n * @private\r\n */\r\nexport function _excludeInitialState(data: any): void {\r\n common.deleteProp(data, \"initialState\");\r\n}\r\n\r\n/**\r\n * Extracts the AGOL itemId for each layer or table object in a list using the url.\r\n *\r\n * @param layerList List of map layers or tables\r\n * @param dependencies Current list of dependencies\r\n * @param authentication Credentials for any requests\r\n * @returns List of dependencies ids and url/itemId hash\r\n * @private\r\n */\r\nexport function _getLayerIds(\r\n layerList: any[],\r\n dependencies: string[],\r\n authentication: common.UserSession\r\n): Promise<any> {\r\n return new Promise<any>((resolve, reject) => {\r\n const urlHash: any = {};\r\n\r\n const options: any = {\r\n f: \"json\",\r\n authentication: authentication\r\n };\r\n const layerPromises: Array<Promise<any>> = [];\r\n const layerChecks: any = {};\r\n const layers: any[] = layerList.filter(layer => {\r\n if (layer.url && layer.url.indexOf(\"{{velocityUrl}}\") < 0) {\r\n const results: any = /.+FeatureServer/g.exec(layer.url);\r\n const baseUrl: string =\r\n Array.isArray(results) && results.length > 0 ? results[0] : undefined;\r\n if (baseUrl) {\r\n // avoid redundant checks when we have a layer with subLayers\r\n if (Object.keys(layerChecks).indexOf(baseUrl) < 0) {\r\n layerChecks[baseUrl] = common.rest_request(layer.url, options);\r\n }\r\n layerPromises.push(layerChecks[baseUrl]);\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n } else {\r\n return false;\r\n }\r\n });\r\n\r\n if (layerPromises.length > 0) {\r\n Promise.all(layerPromises).then(\r\n serviceResponses => {\r\n serviceResponses.forEach((serviceResponse, i) => {\r\n if (common.getProp(serviceResponse, \"serviceItemId\")) {\r\n const id: string = serviceResponse.serviceItemId;\r\n if (dependencies.indexOf(id) < 0) {\r\n dependencies.push(id);\r\n }\r\n urlHash[layers[i].url] = id;\r\n }\r\n });\r\n resolve({\r\n dependencies: dependencies,\r\n urlHash: urlHash\r\n });\r\n },\r\n e => reject(common.fail(e))\r\n );\r\n } else {\r\n resolve({\r\n dependencies: dependencies,\r\n urlHash: urlHash\r\n });\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Templatizes the url and item id for layers or tables within the webmap.\r\n *\r\n * @param layerList List of map layers or tables\r\n * @param urlHash Lookup object for analysis layers\r\n * @returns void\r\n * @private\r\n */\r\nexport function _templatizeWebmapLayerIdsAndUrls(\r\n layerList = [] as any[],\r\n urlHash: any\r\n): void {\r\n layerList.forEach((layer: any) => {\r\n if (layer.url) {\r\n const layerId = layer.url.substr(\r\n (layer.url as string).lastIndexOf(\"/\") + 1\r\n );\r\n const id: any =\r\n Object.keys(urlHash).indexOf(layer.url) > -1\r\n ? urlHash[layer.url]\r\n : undefined;\r\n if (id) {\r\n layer.url = common.templatizeTerm(id, id, \".layer\" + layerId + \".url\");\r\n layer.itemId = common.templatizeTerm(\r\n id,\r\n id,\r\n \".layer\" + layerId + \".itemId\"\r\n );\r\n }\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Templatize field references.\r\n *\r\n * @param solutionTemplate The solution item template\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns The solutionTemplate with templatized field references\r\n */\r\nexport function postProcessFieldReferences(\r\n solutionTemplate: common.IItemTemplate,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): common.IItemTemplate {\r\n const paths: string[] = [\r\n \"data.operationalLayers\",\r\n \"data.tables\",\r\n \"data.applicationProperties.viewing.search.layers\"\r\n ];\r\n paths.forEach(p => _templatizeProperty(solutionTemplate, datasourceInfos, p));\r\n return solutionTemplate;\r\n}\r\n\r\n/**\r\n * Templatize field references.\r\n *\r\n * @param solutionTemplate The solution item template\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @param path A string path to the object property to templatize\r\n * @private\r\n */\r\nexport function _templatizeProperty(\r\n solutionTemplate: common.IItemTemplate,\r\n datasourceInfos: common.IDatasourceInfo[],\r\n path: string\r\n): void {\r\n const objs: any[] = common.getProp(solutionTemplate, path);\r\n if (objs) {\r\n common.setProp(solutionTemplate, path, _templatize(objs, datasourceInfos));\r\n }\r\n}\r\n\r\n/**\r\n * Templatize field references.\r\n *\r\n * @param objs Can be operationalLayers or tables or appProperties search layers\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns updated instances of the objects\r\n * @private\r\n */\r\nexport function _templatize(\r\n objs: any[],\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): any[] {\r\n objs.forEach(obj => {\r\n const ds: common.IDatasourceInfo = _getDatasourceInfo(obj, datasourceInfos);\r\n if (ds) {\r\n const fieldNames: string[] = ds.fields.map(f => f.name);\r\n\r\n common._templatizePopupInfo(obj, ds, ds.basePath, ds.itemId, fieldNames);\r\n\r\n common._templatizeDefinitionEditor(obj, ds.basePath, fieldNames);\r\n\r\n if (obj.layerDefinition) {\r\n common._templatizeDrawingInfo(\r\n obj.layerDefinition,\r\n ds.basePath,\r\n fieldNames\r\n );\r\n\r\n common._templatizeDefinitionExpression(\r\n obj.layerDefinition,\r\n ds.basePath,\r\n fieldNames\r\n );\r\n }\r\n\r\n // used for applicationProperties search layers\r\n const fieldName: any = common.getProp(obj, \"field.name\");\r\n if (fieldName) {\r\n common.setProp(\r\n obj,\r\n \"field.name\",\r\n common._templatizeFieldName(fieldName, obj, ds.itemId, ds.basePath)\r\n );\r\n }\r\n }\r\n });\r\n\r\n return objs;\r\n}\r\n\r\n/**\r\n * Get datasourceInfo by map layer id\r\n *\r\n * @param obj Can be operationalLayer or table or appProperties search layer\r\n * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references\r\n * @returns datasourceInfo for the given object id\r\n * @private\r\n */\r\nexport function _getDatasourceInfo(\r\n obj: any,\r\n datasourceInfos: common.IDatasourceInfo[]\r\n): any {\r\n let datasourceInfo: any;\r\n datasourceInfos.some(ds => {\r\n if (ds.ids.indexOf(obj.id) > -1) {\r\n datasourceInfo = ds;\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n });\r\n return datasourceInfo;\r\n}\r\n","/** @license\r\n * Copyright 2020 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\nimport * as common from \"@esri/solution-common\";\r\nimport * as dashboard from \"../dashboard\";\r\nimport * as notebook from \"../notebook\";\r\nimport * as oic from \"../oic\";\r\nimport * as quickcapture from \"../quickcapture\";\r\nimport * as webmap from \"../webmap\";\r\nimport * as webmappingapplication from \"../webmappingapplication\";\r\nimport * as workforce from \"../workforce\";\r\n\r\n/**\r\n * Converts an item into a template.\r\n *\r\n * @param solutionItemId The solution to contain the template\r\n * @param itemInfo Info about the item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements\r\n *\r\n * @returns A promise that will resolve when the template has been created\r\n */\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession,\r\n templateDictionary: any\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>((resolve, reject) => {\r\n // Init template\r\n const itemTemplate: common.IItemTemplate = common.createInitializedItemTemplate(\r\n itemInfo\r\n );\r\n\r\n // Templatize item info property values\r\n itemTemplate.item.id = common.templatizeTerm(\r\n itemTemplate.item.id,\r\n itemTemplate.item.id,\r\n \".itemId\"\r\n );\r\n\r\n // Request related items\r\n const relatedPromise = common.getItemRelatedItemsInSameDirection(\r\n itemTemplate.itemId,\r\n \"forward\",\r\n srcAuthentication\r\n );\r\n\r\n // Perform type-specific handling\r\n let dataPromise = Promise.resolve({});\r\n switch (itemInfo.type) {\r\n case \"Dashboard\":\r\n case \"Feature Collection\":\r\n case \"Feature Service\":\r\n case \"Hub Initiative\":\r\n case \"Hub Page\":\r\n case \"Hub Site Application\":\r\n case \"Insights Model\":\r\n case \"Oriented Imagery Catalog\":\r\n case \"Project Package\":\r\n case \"Workforce Project\":\r\n case \"Web Map\":\r\n case \"Web Mapping Application\":\r\n case \"Web Scene\":\r\n case \"Notebook\":\r\n dataPromise = new Promise(resolveJSON => {\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n common\r\n .getItemDataAsJson(itemTemplate.itemId, srcAuthentication)\r\n .then(json => resolveJSON(json));\r\n });\r\n break;\r\n case \"Form\":\r\n dataPromise = common.getItemDataAsFile(\r\n itemTemplate.itemId,\r\n itemTemplate.item.name,\r\n srcAuthentication\r\n );\r\n break;\r\n case \"QuickCapture Project\":\r\n dataPromise = common.getItemResourcesFiles(\r\n itemTemplate.itemId,\r\n srcAuthentication\r\n );\r\n break;\r\n }\r\n\r\n // Errors are handled as resolved empty values; this means that there's no `reject` clause to handle, hence:\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n Promise.all([dataPromise, relatedPromise]).then(responses => {\r\n const [itemDataResponse, relatedItemsResponse] = responses;\r\n\r\n // need to pre-process for velocity urls before they could be templatized by other processors\r\n itemTemplate.data = common.updateVelocityReferences(\r\n itemDataResponse,\r\n itemInfo.type,\r\n templateDictionary\r\n );\r\n const relationships = relatedItemsResponse;\r\n\r\n // Save the mappings to related items & add those items to the dependencies, but not WMA Code Attachments\r\n itemTemplate.dependencies = [] as string[];\r\n itemTemplate.relatedItems = [] as common.IRelatedItems[];\r\n\r\n relationships.forEach(relationship => {\r\n /* istanbul ignore else */\r\n if (relationship.relationshipType !== \"WMA2Code\") {\r\n itemTemplate.relatedItems.push(relationship);\r\n relationship.relatedItemIds.forEach(relatedItemId => {\r\n if (itemTemplate.dependencies.indexOf(relatedItemId) < 0) {\r\n itemTemplate.dependencies.push(relatedItemId);\r\n }\r\n });\r\n }\r\n });\r\n\r\n let wrapupPromise = Promise.resolve(null);\r\n let templateModifyingPromise = Promise.resolve(itemTemplate);\r\n switch (itemInfo.type) {\r\n case \"Dashboard\":\r\n dashboard.convertItemToTemplate(itemTemplate);\r\n break;\r\n case \"Form\":\r\n // Store the form's data in the solution resources, not in template\r\n itemTemplate.data = null;\r\n\r\n // Store form data\r\n if (itemDataResponse) {\r\n const originalFilename =\r\n itemTemplate.item.name || (itemDataResponse as File).name;\r\n const filename =\r\n originalFilename && originalFilename !== \"undefined\"\r\n ? originalFilename\r\n : `${itemTemplate.itemId}.zip`;\r\n itemTemplate.item.name = filename;\r\n const storageName = common.convertItemResourceToStorageResource(\r\n itemTemplate.itemId,\r\n filename,\r\n common.SolutionTemplateFormatVersion,\r\n common.SolutionResourceType.data\r\n );\r\n wrapupPromise = new Promise<void>(\r\n (resolveDataStorage, rejectDataStorage) => {\r\n common\r\n .addResourceFromBlob(\r\n itemDataResponse,\r\n solutionItemId,\r\n storageName.folder,\r\n filename,\r\n destAuthentication\r\n )\r\n .then(() => {\r\n // Update the template's resources\r\n itemTemplate.resources.push(\r\n storageName.folder + \"/\" + storageName.filename\r\n );\r\n resolveDataStorage();\r\n }, rejectDataStorage);\r\n }\r\n );\r\n }\r\n break;\r\n case \"Notebook\":\r\n notebook.convertNotebookToTemplate(itemTemplate);\r\n break;\r\n case \"Oriented Imagery Catalog\":\r\n templateModifyingPromise = oic.convertItemToTemplate(\r\n itemTemplate,\r\n destAuthentication,\r\n srcAuthentication\r\n );\r\n break;\r\n case \"Web Map\":\r\n case \"Web Scene\":\r\n templateModifyingPromise = webmap.convertItemToTemplate(\r\n itemTemplate,\r\n destAuthentication,\r\n srcAuthentication\r\n );\r\n break;\r\n case \"Web Mapping Application\":\r\n if (itemDataResponse) {\r\n templateModifyingPromise = webmappingapplication.convertItemToTemplate(\r\n itemTemplate,\r\n destAuthentication,\r\n srcAuthentication\r\n );\r\n }\r\n break;\r\n case \"Workforce Project\":\r\n templateModifyingPromise = workforce.convertItemToTemplate(\r\n itemTemplate,\r\n destAuthentication,\r\n srcAuthentication\r\n );\r\n break;\r\n case \"QuickCapture Project\":\r\n templateModifyingPromise = quickcapture.convertQuickCaptureToTemplate(\r\n itemTemplate\r\n );\r\n break;\r\n }\r\n\r\n wrapupPromise.then(\r\n () => {\r\n templateModifyingPromise.then(resolve, err =>\r\n reject(common.fail(err))\r\n );\r\n },\r\n err => reject(common.fail(err))\r\n );\r\n });\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 simple item types.\r\n *\r\n * @module simple-types\r\n */\r\n\r\nimport * as dashboard from \"./dashboard\";\r\nimport * as webmap from \"./webmap\";\r\nimport * as webmappingapplication from \"./webmappingapplication\";\r\n\r\nimport {\r\n ICreateItemFromTemplateResponse,\r\n IDatasourceInfo,\r\n IItemProgressCallback,\r\n IItemTemplate,\r\n IUpdateItemResponse,\r\n updateItemTemplateFromDictionary,\r\n UserSession\r\n} from \"@esri/solution-common\";\r\n\r\n// Need to import collectively to enable spying\r\nimport * as simpleTypeHelpers from \"./helpers/simple-type-helpers\";\r\n\r\n/**\r\n * Converts an item into a template.\r\n *\r\n * @param solutionItemId The solution to contain the template\r\n * @param itemInfo Info about the item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements\r\n * @returns A promise that will resolve when the template has been created\r\n */\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any,\r\n destAuthentication: UserSession,\r\n srcAuthentication: UserSession,\r\n templateDictionary: any\r\n): Promise<IItemTemplate> {\r\n return simpleTypeHelpers.convertItemToTemplate(\r\n solutionItemId,\r\n itemInfo,\r\n destAuthentication,\r\n srcAuthentication,\r\n templateDictionary\r\n );\r\n}\r\n\r\n/**\r\n * Delegate to simpleType creator\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 return simpleTypeHelpers.createItemFromTemplate(\r\n template,\r\n templateDictionary,\r\n destinationAuthentication,\r\n itemProgressCallback\r\n );\r\n}\r\n\r\n/**\r\n * Templatizes field references within specific template types.\r\n * Currently only handles web mapping applications\r\n *\r\n * @param template A solution template\r\n * @param datasourceInfos A list of objects that store key datasource info used to templatizing field references\r\n * @param type The item type\r\n * @returns The updated solution template\r\n */\r\nexport function postProcessFieldReferences(\r\n solutionTemplate: IItemTemplate,\r\n datasourceInfos: IDatasourceInfo[],\r\n type: string\r\n): IItemTemplate {\r\n switch (type) {\r\n case \"Web Mapping Application\":\r\n webmappingapplication.postProcessFieldReferences(\r\n solutionTemplate,\r\n datasourceInfos\r\n );\r\n break;\r\n case \"Dashboard\":\r\n dashboard.postProcessFieldReferences(solutionTemplate, datasourceInfos);\r\n break;\r\n case \"Web Map\":\r\n webmap.postProcessFieldReferences(solutionTemplate, datasourceInfos);\r\n break;\r\n }\r\n return solutionTemplate;\r\n}\r\n\r\n/**\r\n * Simple Type post-processing actions\r\n *\r\n * @param {string} itemId The item ID\r\n * @param {string} type The template type\r\n * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} authentication The destination session info\r\n * @returns Promise resolving to successfulness of update\r\n */\r\nexport function postProcess(\r\n itemId: string,\r\n type: string,\r\n itemInfos: any[],\r\n template: IItemTemplate,\r\n templates: IItemTemplate[],\r\n templateDictionary: any,\r\n authentication: UserSession\r\n): Promise<IUpdateItemResponse> {\r\n return updateItemTemplateFromDictionary(\r\n itemId,\r\n templateDictionary,\r\n authentication\r\n );\r\n}\r\n"],"names":["convertItemToTemplate","itemTemplate","forEach","path","objs","common","getProp","Array","isArray","obj","type","dependencies","indexOf","itemId","push","templatizeTerm","datasets","dataset","layerId","dataSource","undefined","_getDatasourceDependencies","_extractDependencies","postProcessFieldReferences","solutionTemplate","datasourceInfos","updatePaths","cleanLayerBasedItemId","cleanLayerId","some","ds","_updateReferences","id","dashboardLayerId","split","ids","_updateDatasourceReferences","setProp","map","_obj","events","event","_event","actions","action","_action","fieldMap","targetId","datasourceInfo","_getDatasourceInfo","fields","basePath","m","_m","targetName","templatizeFieldReferences","_dataset","_templatizeByDatasource","_templatize","info","di","dashboardWidgetId","hasRef","references","matches","destAuthentication","srcAuthentication","Promise","resolve","reject","portalUrl","item","url","templatizedUrl","iSep","placeholder","SERVER_NAME","substring","lastIndexOf","replace","model","processor","_getGenericWebAppDependencies","hasAnyKeyword","_getWABDependencies","paths","_templatizeIdPath","_templatizeIdPaths","setValues","GEOMETRY_SERVER_NAME","authentication","dataSources","Object","keys","length","pendingRequests","k","substr","urlResults","findUrls","resolveReq","rejectReq","handleServiceRequests","serviceRequests","requestUrls","testString","then","response","e","fail","all","templatizeDatasources","templatizeWidgets","_itemTemplate","updatedItemTemplate","widgetPath","values","JSON","stringify","parse","templatizeValues","_updatedItemTemplate","isOnScreen","widgets","widget","config","sWidgets","objString","i","serviceResponses","serviceResponse","serviceTemplate","serviceItemId","hasOwnProperty","replaceUrl","options","f","results","match","NA_SERVER_NAME","GEOCODE_SERVER_NAME","rest_request","newUrl","validateFullUrl","enforceFullUrl","re","RegExp","base","subString","getProps","deps","v","_templatizeObject","objects","updateKeyObjects","templatizeKeys","name","_templatizeObjectArray","hasDatasources","filter","urlTest","isNaN","hasMapLayerId","test","_templatizeParentByURL","_templatizeParentByWebMapLayerId","_prioritizedTests","replaceOrder","_getSortOrder","sort","a","b","_getReplaceOrder","layerUrlTest","clone","c","idTest","parsedProp","error","createItemFromTemplate","template","templateDictionary","destinationAuthentication","itemProgressCallback","EItemProgressStatus","Started","newItemTemplate","cloneObject","replaceInTemplate","data","thumbnail","createItemWithData","folderId","createResponse","Created","estimatedDeploymentCostFactor","postProcess","hasUnresolvedVariables","originalURL","customProcDef","relationshipsDef","relatedItems","updatedRelatedItems","templatizeIds","addForwardItemRelationships","originalTemplate","newlyCreatedItem","updateOptions","updateDef","updateItem","itemInfo","tags","title","typeKeywords","relationshipType","originItemId","checkUrlPathTermination","createItemWithDataDef","webmappingapplication.fineTuneCreatedItem","fineTuneCreatedWorkforceItem","workforce.fineTuneCreatedItem","notebook.fineTuneCreatedItem","resolve2","reject2","updateItemURL","Finished","Cancelled","removeItem","generateEmptyCreationResponse","Failed","Ignored","jsonToBlob","convertNotebookToTemplate","deleteProps","dataString","verifiedIds","regEx","props","cells","cell","fineTuneCreatedItem","jsonToFile","solutionItemId","notebookHelpers.convertItemToTemplate","notebookHelpers.createItemFromTemplate","itemInfos","templates","updateItemTemplateFromDictionary","properties","layerURLs","ServiceURL","OverviewURL","urlHash","layerPromises","layerChecks","filteredLayerURLs","layerURL","exec","baseUrl","_getLayerIds","_templatizeOicLayerUrl","templatizedURL","convertQuickCaptureToTemplate","applicationRequest","applicationName","getBlobText","result","application","_templatizeApplication","_templatizeId","_templatizeAdminEmail","featureServiceItemId","_updateDependencies","_templatizeUrl","idPath","urlPath","quickcaptureHelpers.convertItemToTemplate","quickcaptureHelpers.createItemFromTemplate","updateItemResourceText","layers","operationalLayers","tables","layerList","layer","concat","_templatizeWebmapLayerIdsAndUrls","deleteProp","p","fieldNames","_templatizePopupInfo","_templatizeDefinitionEditor","layerDefinition","_templatizeDrawingInfo","_templatizeDefinitionExpression","fieldName","_templatizeFieldName","_templatizeProperty","createInitializedItemTemplate","relatedPromise","getItemRelatedItemsInSameDirection","dataPromise","resolveJSON","getItemDataAsJson","json","getItemDataAsFile","getItemResourcesFiles","responses","itemDataResponse","relatedItemsResponse","updateVelocityReferences","relationships","relationship","relatedItemIds","relatedItemId","wrapupPromise","templateModifyingPromise","dashboard.convertItemToTemplate","originalFilename","filename","storageName","convertItemResourceToStorageResource","SolutionTemplateFormatVersion","SolutionResourceType","resolveDataStorage","rejectDataStorage","addResourceFromBlob","folder","resources","notebook.convertNotebookToTemplate","oic.convertItemToTemplate","webmap.convertItemToTemplate","webmappingapplication.convertItemToTemplate","convertWorkforceItemToTemplate","workforce.convertItemToTemplate","quickcapture.convertQuickCaptureToTemplate","err","simpleTypeHelpers.convertItemToTemplate","simpleTypeHelpers.createItemFromTemplate","webmappingapplication.postProcessFieldReferences","dashboard.postProcessFieldReferences","webmap.postProcessFieldReferences"],"mappings":";;;;;;;;;;;;;;;;;uoBAiFgBA,EACdC,GAEA,gBAYAA,GA8BA,MA3B8B,CAC5B,eACA,6BACA,2BACA,sBAGUC,SAAQC,IAClB,MAAMC,EAA2BC,EAAOC,QAAQL,EAAcE,GAC1DI,MAAMC,QAAQJ,IAChBA,EAAKF,SAAQO,IAEM,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Q,GACrC1Q,EAAOhE,EAAOwG,KAAKkO,KACpB,IAEHA,GAAO1Q,EAAOhE,EAAOwG,KAAKkO,KAC3B,GACD,GAEN,2JClLE7F,EACAhC,EACAjJ,EACAC,EACAmH,GAEA,OAAO2J,EACL9F,EACAhC,EACAjJ,EACAC,EACAmH,EAEJ,kCAWED,EACAC,EACAC,EACAC,GAEA,OAAO0J,EACL7J,EACAC,EACAC,EACAC,EAEJ,sCAYE/J,EACAC,EACAf,GAEA,OAAQA,GACN,IAAK,0BACHwU,EACE1T,EACAC,GAEF,MACF,IAAK,YACH0T,EAAqC3T,EAAkBC,GACvD,MACF,IAAK,UACH2T,EAAkC5T,EAAkBC,GAGxD,OAAOD,CACT,uBAaEX,EACAH,EACA2O,EACAjE,EACAkE,EACAjE,EACA3F,GAEA,OAAO6J,mCACL1O,EACAwK,EACA3F,EAEJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esri/solution-simple-types",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Manages the creation and deployment of simple item types for @esri/solution.js.",
|
|
5
5
|
"main": "dist/node/index.js",
|
|
6
6
|
"unpkg": "dist/umd/simple-types.umd.min.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"@esri/arcgis-rest-portal": "3.4.3",
|
|
19
19
|
"@esri/arcgis-rest-request": "3.4.3",
|
|
20
20
|
"@esri/arcgis-rest-service-admin": "3.4.3",
|
|
21
|
-
"@esri/hub-common": "
|
|
22
|
-
"@esri/hub-teams": "
|
|
21
|
+
"@esri/hub-common": "^10.0.0-next.3",
|
|
22
|
+
"@esri/hub-teams": "^10.0.0-next.3",
|
|
23
23
|
"rollup": "2.66.1"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
"@esri/arcgis-rest-portal": "3.4.3",
|
|
29
29
|
"@esri/arcgis-rest-request": "3.4.3",
|
|
30
30
|
"@esri/arcgis-rest-service-admin": "3.4.3",
|
|
31
|
-
"@esri/hub-common": "
|
|
32
|
-
"@esri/hub-teams": "
|
|
31
|
+
"@esri/hub-common": "^10.0.0-next.3",
|
|
32
|
+
"@esri/hub-teams": "^10.0.0-next.3"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@esri/solution-common": "^1.
|
|
36
|
-
"@esri/solution-feature-layer": "^1.
|
|
37
|
-
"@esri/solution-file": "^1.
|
|
38
|
-
"@esri/solution-group": "^1.
|
|
35
|
+
"@esri/solution-common": "^1.4.1",
|
|
36
|
+
"@esri/solution-feature-layer": "^1.4.1",
|
|
37
|
+
"@esri/solution-file": "^1.4.1",
|
|
38
|
+
"@esri/solution-group": "^1.4.1",
|
|
39
39
|
"tslib": "1.14.1"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"esri",
|
|
91
91
|
"ES6"
|
|
92
92
|
],
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "71006b142f9473cdd1b4a8b9fad0d6bfe50e12bd"
|
|
94
94
|
}
|