import { request } from "@esri/arcgis-rest-request" ; import { ISharingOptions , ISharingResponse , isItemOwner , getSharingUrl , isOrgAdmin } from "./helpers" ; export interface ISetAccessOptions extends ISharingOptions { /**
     * "private" indicates that the item can only be accessed by the user. "public" means accessible to anyone. An item shared to the organization has an access level of "org".
     */ access : "private" | "org" | "public" ; } param requestOptions returns export function setItemAccess ( requestOptions ) { const url = getSharingUrl ( requestOptions ) ; if ( isItemOwner ( requestOptions ) ) { return updateItemAccess ( url , requestOptions ) ; } else { return isOrgAdmin ( requestOptions ) . then ( admin => { if ( admin ) { return updateItemAccess ( url , requestOptions ) ; } else { throw Error ( `This item can not be shared by ${ requestOptions . authentication . username }. They are neither the item owner nor an organization admin.` ) ; } } ) ; } } function updateItemAccess ( url , requestOptions ) { requestOptions . params = { org : false , everyone : false , ... requestOptions . params } ; if ( requestOptions . access === "private" ) { requestOptions . params . groups = " " ; } if ( requestOptions . access === "org" ) { requestOptions . params . org = true ; } if ( requestOptions . access === "public" ) { requestOptions . params . account = true ; requestOptions . params . everyone = true ; } return request ( url , requestOptions ) ; }