import { IModel , IHubRequestOptions , cloneObject , propifyString , createId , normalizeSolutionTemplateItem , IModelTemplate , getProp , replaceItemId , getItemAssets } from "@esri/hub-common" ; import { getSiteItemType } from "./get-site-item-type" ; import { IItem } from "@esri/arcgis-rest-types" ; import { SITE_SCHEMA_VERSION } from "./site-schema-version" ; import { convertLayoutToTemplate } from "./layout" ; import { getSiteDependencies } from "./get-site-dependencies" ; param { Object } model param { IHubRequestOptions } hubRequestOptions export function convertSiteToTemplate ( model , hubRequestOptions ) { const tmpl = ( cloneObject ( model ) as unknown ) as IModelTemplate ; tmpl . type = getSiteItemType ( hubRequestOptions . isPortal ) ; tmpl . key = `${ propifyString ( model . item . title ) }_${ createId ( "i" ) }` ; tmpl . itemId = model . item . id ; tmpl . item = normalizeSolutionTemplateItem ( tmpl . item as IItem ) ; delete tmpl . item . url ; tmpl . item . properties = { schemaVersion : SITE_SCHEMA_VERSION , children : [ ] } ; tmpl . item . title = "{{solution.title}}" ; tmpl . data . values . subdomain = "{{solution.subdomain}}" ; tmpl . data . values . defaultHostname = "{{solution.defaultHostname}}" ; tmpl . data . values . title = "{{solution.title}}" ; tmpl . data . values . subdomain = "{{solution.subdomain}}" ; tmpl . data . values . defaultHostname = "{{solution.defaultHostname}}" ; delete tmpl . data . catalog ; delete tmpl . data . values . collaborationGroupId ; [ "updatedAt" , "updatedBy" , "clientId" , "siteId" ] . forEach ( p => { tmpl . data . values [ p ] = "" ; } ) ; [ "customHostname" , "externalUrl" , "contentGroupId" , "followersGroupId" , "groups" ] . forEach ( p => { delete tmpl . data . values [ p ] ; } ) ; if ( getProp ( tmpl , "data.values.defaultExtent" ) ) { tmpl . data . values . defaultExtent = "{{organization.defaultExtent}}" ; } if ( getProp ( tmpl , "data.values.map.basemaps.primary.extent" ) ) { tmpl . data . values . map . basemaps . primary . extent = "{{organization.defaultExtent}}" ; } const layoutConversion = convertLayoutToTemplate ( tmpl . data . values . layout ) ; tmpl . data . values . layout = layoutConversion . layout ; tmpl . data = replaceItemId ( tmpl . data , tmpl . itemId ) ; tmpl . dependencies = getSiteDependencies ( model ) ; return getItemAssets ( model . item , hubRequestOptions ) . then ( assets => { tmpl . assets = assets ; return tmpl ; } ) ; }