import { cloneObject , getProp , deepSet , IModel } from "@esri/hub-common" ; import { _getPortalDomainTypeKeyword } from "./_get-portal-domain-type-keyword" ; import { _ensureTypeAndTags } from "./_ensure-type-and-tags" ; import { SITE_UI_VERSION } from "./site-ui-version" ; param { Object } model param { Object } currentUser param { Boolean } isPortal export function ensureRequiredSiteProperties ( model , username , isPortal = false ) { model = cloneObject ( model ) ; model . item . owner = username ; model . item . access = "private" ; if ( ! Array . isArray ( model . item . typeKeywords ) ) { model . item . typeKeywords = [ ] ; } model . data . values . updatedAt = new Date ( ) . toISOString ( ) ; model . data . values . updatedBy = username ; if ( isPortal ) { model . item . typeKeywords . push ( _getPortalDomainTypeKeyword ( model . data . values . subdomain ) ) ; } if ( ! model . item . url ) { const hostname = getProp ( model , "data.values.customHostname" ) || getProp ( model , "data.values.defaultHostname" ) ; let protocol = "https" ; if ( model . data . values . customHostname ) { protocol = "http" ; } model . item . url = `${ protocol }://${ hostname }` ; } if ( ! Array . isArray ( getProp ( model , "data.values.pages" ) ) ) { deepSet ( model , "data.values.pages" , [ ] ) ; } deepSet ( model , "data.values.uiVersion" , SITE_UI_VERSION ) ; model = _ensureTypeAndTags ( model , isPortal ) ; const caps = [ "api_explorer" , "pages" , "my_data" , "social_logins" , "json_chart_card" , "document_iframes" , "items_view" , "app_page" , "underlinedLinks" , "globalNav" , ] ; if ( ! isPortal ) { caps . push ( "socialSharing" ) ; } deepSet ( model , "data.values.capabilities" , caps ) ; return model ; }