UNPKG

@esri/arcgis-rest-portal

Version:

ArcGIS Online and Enterprise content and user helpers for @esri/arcgis-rest-request

8 lines (7 loc) 26.6 kB
/* @preserve * @esri/arcgis-rest-portal - v4.6.1 - Apache-2.0 * Copyright (c) 2017-2025 Esri, Inc. * Wed Aug 13 2025 20:30:31 GMT+0000 (Coordinated Universal Time) */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@esri/arcgis-rest-request")):"function"==typeof define&&define.amd?define(["exports","@esri/arcgis-rest-request"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).arcgisRest=e.arcgisRest||{},e.arcgisRest)}(this,(function(e,t){"use strict";function r(e={}){return e.portal?t.cleanUrl(e.portal):e.authentication&&"string"!=typeof e.authentication?e.authentication.portal:"https://www.arcgis.com/sharing/rest"}function n(e){return e.owner?Promise.resolve(e.owner):e.item&&e.item.owner?Promise.resolve(e.item.owner):e.authentication&&e.authentication.getUsername?e.authentication.getUsername():Promise.reject(new Error("Could not determine the owner of this item. Pass the `owner`, `item.owner`, or `authentication` option."))}function s(e){return Array.isArray(e)&&Array.isArray(e[0])&&Array.isArray(e[1])}function o(e){return e.join(",")}function i(e){return n(e).then((n=>{const i=e.folderId?`${r(e)}/content/users/${n}/${e.folderId}/items/${e.item.id}/update`:`${r(e)}/content/users/${n}/items/${e.item.id}/update`;return e.params=Object.assign(Object.assign({},e.params),e.item),e.params.extent&&s(e.params.extent)&&(e.params.extent=o(e.params.extent)),t.request(i,e)}))}function a(e){return e.multipart&&!e.filename?Promise.reject(new Error("The filename is required for a multipart request.")):n(e).then((n=>{const i=`${r(e)}/content/users/${n}`;let a=`${i}/addItem`;e.folderId&&(a=`${i}/${e.folderId}/addItem`),e.params=Object.assign(Object.assign({},e.params),e.item),e.params.extent&&s(e.params.extent)&&(e.params.extent=o(e.params.extent));const u=t.appendCustomParams(e,["owner","folderId","file","dataUrl","text","async","multipart","filename","overwrite"],{params:Object.assign({},e.params)});return t.request(a,u)}))}const u=/[\x00-\x1F\x7F-\x9F\xA0]/g;function c(e){return e.replace(u,"")}const m=(e,t)=>`${"string"==typeof t?t:r(t)}/content/items/${e}`;function d(e,t){const{fileName:r="iteminfo.xml",readAs:n="text"}=t||{};return p(e,`/info/${r}`,n,Object.assign({httpMethod:"GET"},t))}function p(e,r,n,s){const o=`${m(e,s)}${r}`,i=Object.assign({params:{}},s),a=i.rawResponse;return i.rawResponse=!0,i.params.f=null,t.request(o,i).then((e=>a?e:"json"!==n?e[n]():e.text().then((e=>JSON.parse(c(e))))))}function h(e,n){const s=`${r(n)}/community/groups/${e}`,o=Object.assign({httpMethod:"GET"},n);return t.request(s,o)}function g(e,t){const n=t||e.authentication.username,s=e.owner||n;return`${r(e)}/content/users/${encodeURIComponent(s)}/items/${e.id}/share`}function l(e,t){const r=t||e.authentication.username;return(e.owner||r)===r}function f(e){return e.authentication.getUser().then((e=>e&&"org_admin"===e.role&&!e.roleId))}function $(e){return h(e.groupId,e).then((e=>e.userMembership.memberType)).catch((()=>"none"))}class b{constructor(e=""){this.termStack=[],this.rangeStack=[],this.openGroups=0,this.q=e}match(...e){return this.termStack=this.termStack.concat(e),this}in(e){const r=`\`in(${e?`"${e}"`:""})\``;return this.hasRange||this.hasTerms?(e&&"*"!==e&&(this.q+=`${e}:`),this.commit()):(t.warn(`${r} was called with no call to \`match(...)\` or \`from(...)\`/\`to(...)\`. Your query was not modified.`),this)}startGroup(){return this.commit(),this.openGroups>0&&(this.q+=" "),this.openGroups++,this.q+="(",this}endGroup(){return this.openGroups<=0?(t.warn("`endGroup(...)` was called without calling `startGroup(...)` first. Your query was not modified."),this):(this.commit(),this.openGroups--,this.q+=")",this)}and(){return this.addModifier("and")}or(){return this.addModifier("or")}not(){return this.addModifier("not")}from(e){return this.hasTerms?(t.warn('`from(...)` is not allowed after `match(...)` try using `.from(...).to(...).in(...)`. Optionally, you may see this because dates are incorrectly formatted. Dates should be a primative Date value, aka a number in milliseconds or Date object, ie new Date("2020-01-01"). Your query was not modified.'),this):(this.rangeStack[0]=e,this)}to(e){return this.hasTerms?(t.warn('`to(...)` is not allowed after `match(...)` try using `.from(...).to(...).in(...)`. Optionally, you may see this because dates are incorrectly formatted. Dates should be a primative Date value, aka a number in milliseconds or Date object, ie new Date("2020-01-01"). Your query was not modified.'),this):(this.rangeStack[1]=e,this)}boost(e){return this.commit(),this.q+=`^${e}`,this}toParam(){return this.commit(),this.cleanup(),this.q}clone(){return this.commit(),this.cleanup(),new b(this.q+"")}addModifier(e){return this.currentModifer?(t.warn(`You have called \`${this.currentModifer}()\` after \`${e}()\`. Your current query was not modified.`),this):(this.commit(),""===this.q&&"not"!==e?(t.warn(`You have called \`${e}()\` without calling another method to modify your query first. Try calling \`match()\` first.`),this):(this.currentModifer=e,this.q+=""===this.q?"":" ",this.q+=`${e.toUpperCase()} `,this))}hasWhiteSpace(e){return/\s/g.test(e)}formatTerm(e){return e instanceof Date?e.getTime():"string"==typeof e&&this.hasWhiteSpace(e)?`"${e}"`:e}commit(){return this.currentModifer=void 0,this.hasRange&&(this.q+=`[${this.formatTerm(this.rangeStack[0])} TO ${this.formatTerm(this.rangeStack[1])}]`,this.rangeStack=[void 0,void 0]),this.hasTerms&&(this.q+=this.termStack.map((e=>this.formatTerm(e))).join(" "),this.termStack=[]),this}get hasTerms(){return this.termStack.length>0}get hasRange(){return this.rangeStack.length&&this.rangeStack[0]&&this.rangeStack[1]}cleanup(){if(this.openGroups>0)for(t.warn(`Automatically closing ${this.openGroups} group(s). You can use \`endGroup(...)\` to remove this warning.`);this.openGroups>0;)this.q+=")",this.openGroups--;const e=this.q;this.q=e.replace(/( AND ?| NOT ?| OR ?)*$/,""),e!==this.q&&t.warn("`startGroup(...)` was called without calling `endGroup(...)` first. Your query was not modified."),this.q=this.q.replace(/(\(\))*/,"")}}function y(e,n){let s,o;switch(s="string"==typeof e||e instanceof b?{httpMethod:"GET",params:{q:e}}:t.appendCustomParams(e,["q","num","start","sortField","sortOrder","searchUserAccess","searchUserName","filter","countFields","countSize","categories","categoryFilters"],{httpMethod:"GET"}),n){case"item":o="/search";break;case"group":o="/community/groups";break;case"groupContent":if("string"==typeof e||e instanceof b||!e.groupId)return Promise.reject(new Error("you must pass a `groupId` option to `searchGroupContent`"));o=`/content/groups/${e.groupId}/search`;break;case"communityUser":o="/community/users";break;default:o="/portals/self/users/search"}const i=r(s)+o;return t.request(i,s).then((t=>(t.nextStart&&-1!==t.nextStart&&(t.nextPage=function(){let r;return"string"==typeof e||e instanceof b?r={q:e,start:t.nextStart}:(r=e,r.start=t.nextStart),y(r,n)}),t)))}function I(e){return y(e,"item")}function w(e,t){if(0===e.length)return[];const r=[];for(let n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r}function q(e){const n=e.id,s=`${r(e)}/community/groups/${n}/addUsers`,o=Object.assign({},e,{admins:void 0,users:void 0}),i=[...j("users",e.users,o),...j("admins",e.admins,o)].map((e=>function(e,r){return t.request(e,r).catch((e=>({errors:[e]})))}(s,e)));return Promise.all(i).then(O)}function j(e,t,r){if(!t||t.length<1)return[];return w(t,25).map((t=>function(e,t,r){return Object.assign({},r,{[e]:t,params:Object.assign(Object.assign({},r.params),{[e]:t})})}(e,t,r)))}function O(e){const t=e.filter((e=>e.notAdded)).reduce(((e,t)=>e.concat(t.notAdded)),[]),r=e.filter((e=>e.errors)).reduce(((e,t)=>e.concat(t.errors)),[]),n={notAdded:t};return r.length>0&&(n.errors=r),n}function v(e){const{id:n,users:s}=e,o=`${r(e)}/community/groups/${n}/removeUsers`,i=w(s,25).map((r=>(r=>{const n=Object.assign(Object.assign({},e),{users:r,params:{users:r}});return t.request(o,n).catch((e=>({errors:[e]})))})(r)));return Promise.all(i).then((e=>{const t=t=>e.filter((e=>e[t])).reduce(((e,r)=>e.concat(r[t])),[]),r=t("errors"),n={notRemoved:t("notRemoved")};return r.length?Object.assign(Object.assign({},n),{errors:r}):n}))}function T(e){const t=e.every((e=>e.success)),r=e.reduce(((e,t)=>e.concat(t.errors||[])),[]),n={success:t};return r.length>0&&(n.errors=r),n}function U(e){const n=`${r(e)}/community/groups/${e.id}/updateUsers`,s={authentication:e.authentication,params:{}};return"admin"===e.newMemberType?s.params.admins=e.users:s.params.users=e.users,t.request(n,s)}function G(e){const t=e.every((e=>e.success)),r=e.reduce(((e,t)=>e.concat(t.errors||[])),[]),n={success:t};return r.length>0&&(n.errors=r),n}async function x(e){var t;return e.username?encodeURIComponent(e.username):(null===(t=e.authentication)||void 0===t?void 0:t.username)?encodeURIComponent(e.authentication.username):e.authentication?e.authentication.getUsername().then(encodeURIComponent):void 0}async function P(e){let n,s={httpMethod:"GET"};if("string"==typeof e)n=`https://www.arcgis.com/sharing/rest/community/users/${e}`;else{const t=await x(e);n=`${r(e)}/community/users/${t}`,s=Object.assign(Object.assign({},e),s)}return t.request(n,s)}function S(e,r){return r.params=Object.assign({org:!1,everyone:!1},r.params),"private"===r.access&&(r.params.groups=" "),"org"===r.access&&(r.params.org=!0),"public"===r.access&&(r.params.account=!0,r.params.everyone=!0),t.request(e,r)}function C(e){return I({q:`id: ${e.id} AND group: ${e.groupId}`,start:1,num:10,sortField:"title",authentication:e.authentication,httpMethod:"POST"}).then((t=>{let r=!1;if(t.total>0)return r=t.results.some((t=>t.id===e.id)),r}))}async function E(e,n=!1,s=!1){const o=await e.authentication.getUsername(),i=e.owner||o;let a=`${r(e)}/content/items/${e.id}/share`;return(i===o||n&&!s)&&(a=`${r(e)}/content/users/${i}/items/${e.id}/share`),e.params={groups:e.groupId,confirmItemControl:e.confirmItemControl},t.request(a,e)}function M(e,t,r,n,s){const o=t.groups||[],i=o.find((e=>e.id===s.groupId));if(e.orgId!==t.orgId)throw Error(`User ${t.username} is not a member of the same org as ${e.username}. Consequently they can not be added added to group ${s.groupId} nor can item ${s.id} be shared to the group.`);if(!i&&o.length>511)throw Error(`User ${t.username} already has 512 groups, and can not be added to group ${s.groupId}. Consequently item ${s.id} can not be shared to the group.`);let a,u;if(i)r&&"member"===i.userMembership.memberType?(a=U({id:s.groupId,users:[t.username],newMemberType:"admin",authentication:s.authentication}).then((e=>{const t=e.results.reduce(((e,t)=>(t.success||e.push(t.username),e)),[]);return Promise.resolve({notAdded:t})})).catch((()=>({notAdded:[t.username]}))),u=e=>U({id:s.groupId,users:[t.username],newMemberType:"member",authentication:s.authentication}).then((()=>e)).catch((()=>e))):(a=Promise.resolve({notAdded:[]}),u=e=>Promise.resolve(e));else{const e=r?"admins":"users";a=q({id:s.groupId,[e]:[t.username],authentication:s.authentication}).then((e=>{if(e.errors&&e.errors.length)throw e.errors[0];return e})).catch((()=>({notAdded:[t.username]}))),u=e=>v({id:s.groupId,users:[t.username],authentication:s.authentication}).then((()=>e))}return{promise:a.then((e=>{if(e.notAdded.length)throw new Error(n);return e})),revert:u}}function R(e,r,n){const s=`${n.portal}/portals/self/isServiceNameAvailable`;return t.request(s,{params:{name:e,type:r},httpMethod:"GET",authentication:n})}function A(e,n){const s=e||"self",o=`${r(n)}/portals/${s}`,i=Object.assign({httpMethod:"GET"},n);return t.request(o,i)}e.SearchQueryBuilder=b,e.acceptInvitation=async function(e){const n=await x(e),s=`${r(e)}/community/users/${n}/invitations/${e.invitationId}/accept`,o=Object.assign({},e);return t.request(s,o)},e.addGroupUsers=q,e.addItemData=function(e){const t=Object.assign({item:{id:e.id,text:e.text,file:e.file}},e);return delete t.id,delete t.data,i(t)},e.addItemPart=function(e){const s=e.partNum;return!Number.isInteger(s)||s<1||s>1e4?Promise.reject(new Error("The part number must be an integer between 1 to 10000, inclusive.")):n(e).then((n=>{const o=`${r(e)}/content/users/${n}/items/${e.id}/addPart?partNum=${s}`,i=t.appendCustomParams(e,["file"],{params:Object.assign({},e.params)});return t.request(o,i)}))},e.addItemRelationship=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/addRelationship`,o=t.appendCustomParams(e,["originItemId","destinationItemId","relationshipType"],{params:Object.assign({},e.params)});return t.request(s,o)}))},e.addItemResource=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/addResources`;return e.params=Object.assign({file:e.resource,fileName:e.name,resourcesPrefix:e.prefix,text:e.content,access:e.private?"private":"inherit"},e.params),t.request(s,e)}))},e.bboxToString=o,e.cancelItemUpload=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/cancel`;return t.request(s,e)}))},e.commitItemUpload=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/commit`,o=t.appendCustomParams(e,[],{params:Object.assign(Object.assign({},e.params),e.item)});return t.request(s,o)}))},e.createFolder=function(e){return n(e).then((n=>{const s=`${`${r(e)}/content/users/${n}`}/createFolder`;return e.params=Object.assign({title:e.title},e.params),t.request(s,e)}))},e.createGroup=function(e){const n=`${r(e)}/community/createGroup`;return e.params=Object.assign(Object.assign({},e.params),e.group),t.request(n,e)},e.createGroupNotification=function(e){const n=`${r(e)}/community/groups/${e.id}/createNotification`,s=Object.assign({params:Object.assign({subject:e.subject,message:e.message,users:e.users,notificationChannelType:e.notificationChannelType||"email",clientId:e.clientId,silentNotification:e.silentNotification,notifyAll:!e.users||0===e.users.length},e.params)},e);return t.request(n,s)},e.createItem=function(e){return a(Object.assign({folderId:null},e))},e.createItemInFolder=a,e.createOrgNotification=function(e){const n=`${r(e)}/portals/self/createNotification`,s=function(e){const t=w(e.users,e.batchSize||25);return t.map((t=>function(e,t){const r=Object.assign({},t);return r.params=Object.assign(Object.assign({},r.params),{users:e,subject:t.subject,message:t.message,notificationChannelType:r.notificationChannelType}),r}(t,e)))}(e).map((e=>function(e,r){return t.request(e,r).catch((e=>({errors:[e]})))}(n,e)));return Promise.all(s).then(G)},e.declineInvitation=async function(e){const n=await x(e),s=`${r(e)}/community/users/${n}/invitations/${e.invitationId}/decline`,o=Object.assign({},e);return t.request(s,o)},e.determineOwner=n,e.determineUsername=x,e.ensureMembership=M,e.exportItem=e=>{const{authentication:s,id:o,title:i,exportFormat:a,exportParameters:u}=e;return n(e).then((t=>`${r(e)}/content/users/${t}/export`)).then((e=>t.request(e,{httpMethod:"POST",authentication:s,params:{itemId:o,title:i,exportFormat:a,exportParameters:u}})))},e.getGroup=h,e.getGroupCategorySchema=function(e,n){const s=`${r(n)}/community/groups/${e}/categorySchema`,o=Object.assign({httpMethod:"GET"},n);return t.request(s,o)},e.getGroupContent=function(e,n){const s=`${r(n)}/content/groups/${e}`,o=Object.assign(Object.assign({httpMethod:"GET"},{params:{start:1,num:100}}),n);return n&&n.paging&&(o.params=Object.assign({},n.paging)),t.request(s,o)},e.getGroupUsers=function(e,n){const s=`${r(n)}/community/groups/${e}/users`,o=Object.assign({httpMethod:"GET"},n);return t.request(s,o)},e.getItem=function(e,r){const n=m(e,r),s=Object.assign({httpMethod:"GET"},r);return t.request(n,s)},e.getItemBaseUrl=m,e.getItemData=function(e,r){const n=`${m(e,r)}/data`,s=Object.assign({httpMethod:"GET",params:{}},r);return s.file&&(s.params.f=null),t.request(n,s).catch((e=>{if(!RegExp(/The string did not match the expected pattern|(Unexpected end of (JSON input|data at line 1 column 1))/i).test(e.message))throw e}))},e.getItemGroups=function(e,r){const n=`${m(e,r)}/groups`;return t.request(n,r)},e.getItemInfo=d,e.getItemMetadata=function(e,t){return d(e,Object.assign(Object.assign({},t),{fileName:"metadata/metadata.xml"}))},e.getItemParts=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/parts`;return t.request(s,e)}))},e.getItemResource=function(e,t){const r=t.readAs||"blob";return p(e,`/resources/${t.fileName}`,r,t)},e.getItemResources=function(e,r){const n=`${m(e,r)}/resources`,s=Object.assign({},r);return s.params=Object.assign({num:1e3},s.params),t.request(n,s)},e.getItemStatus=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/status`,o=t.appendCustomParams(e,["jobId","jobType"],{params:Object.assign({},e.params)});return t.request(s,o)}))},e.getPortal=A,e.getPortalSettings=function(e,n){const s=e||"self",o=`${r(n)}/portals/${s}/settings`,i=Object.assign({httpMethod:"GET"},n);return t.request(o,i)},e.getPortalUrl=r,e.getRelatedItems=function(e){const r=`${m(e.id,e)}/relatedItems`,n=Object.assign({httpMethod:"GET",params:{direction:e.direction}},e);return"string"==typeof e.relationshipType?n.params.relationshipType=e.relationshipType:n.params.relationshipTypes=e.relationshipType,delete n.direction,delete n.relationshipType,t.request(r,n)},e.getSelf=function(e){return A(null,e)},e.getSharingUrl=g,e.getUniqueServiceName=function e(t,r,n,s){let o=t;return s&&(o=`${t}_${s}`),R(o,r,n).then((i=>i.available?o:e(t,r,n,s+=1)))},e.getUser=P,e.getUserContent=e=>{const{folderId:s,start:o=1,num:i=10,authentication:a}=e,u=s?`/${s}`:"";return n(e).then((t=>`${r(e)}/content/users/${t}${u}`)).then((e=>t.request(e,{httpMethod:"GET",authentication:a,params:{start:o,num:i}})))},e.getUserInvitation=async function(e){const n=await x(e),s=`${r(e)}/community/users/${n}/invitations/${e.invitationId}`;let o={httpMethod:"GET"};return o=Object.assign(Object.assign({},e),o),t.request(s,o)},e.getUserInvitations=async function(e){let n={httpMethod:"GET"};const s=await x(e),o=`${r(e)}/community/users/${s}/invitations`;return n=Object.assign(Object.assign({},e),n),t.request(o,n)},e.getUserMembership=$,e.getUserNotifications=async function(e){let n={httpMethod:"GET"};const s=await x(e),o=`${r(e)}/community/users/${s}/notifications`;return n=Object.assign(Object.assign({},e),n),t.request(o,n)},e.getUserProperties=async function(e,n){const s=`${r(n)}/community/users/${encodeURIComponent(e)}/properties`,o=await t.request(s,Object.assign({httpMethod:"GET"},n));return o.properties.mapViewer||(o.properties.mapViewer="modern"),o.properties},e.getUserTags=async function(e){const n=await x(e),s=`${r(e)}/community/users/${n}/tags`;return t.request(s,e)},e.getUserUrl=function(e){return`${r(e)}/community/users/${encodeURIComponent(e.username)}`},e.inviteGroupUsers=function(e){const n=e.id,s=`${r(e)}/community/groups/${n}/invite`,o=function(e){const t=w(e.users,25);return t.map((t=>function(e,t){const r=Object.assign({},t);return r.params=Object.assign(Object.assign({},r.params),{users:e,role:r.role,expiration:r.expiration}),r}(t,e)))}(e).map((e=>function(e,r){return t.request(e,r).catch((e=>({errors:[e]})))}(s,e)));return Promise.all(o).then(T)},e.isBBox=s,e.isItemOwner=l,e.isItemSharedWithGroup=C,e.isOrgAdmin=f,e.isServiceNameAvailable=R,e.joinGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/join`;return t.request(n,e)},e.leaveGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/leave`;return t.request(n,e)},e.moveItem=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.itemId}/move`;let o=e.folderId;return o||(o="/"),e.params=Object.assign({folder:o},e.params),t.request(s,e)}))},e.protectGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/protect`;return t.request(n,e)},e.protectItem=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/protect`;return t.request(s,e)}))},e.reassignItem=function(e){return f(e).then((n=>{if(!n)throw Error(`Item ${e.id} can not be reassigned because current user is not an organization administrator.`);const s=`${r(e)}/content/users/${e.currentOwner}/items/${e.id}/reassign`,o={params:{targetUsername:e.targetUsername,targetFolderName:e.targetFolderName},authentication:e.authentication};return t.request(s,o)}))},e.removeFolder=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${encodeURIComponent(n)}/${e.folderId}/delete`;return t.request(s,e)}))},e.removeGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/delete`,s=Object.assign({},e);return t.request(n,s)},e.removeGroupUsers=v,e.removeItem=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/delete`;return t.request(s,e)}))},e.removeItemRelationship=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/deleteRelationship`,o=t.appendCustomParams(e,["originItemId","destinationItemId","relationshipType"],{params:Object.assign({},e.params)});return t.request(s,o)}))},e.removeItemResource=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/removeResources`;return e.params=Object.assign(Object.assign({},e.params),{resource:e.resource}),void 0!==e.deleteAll&&(e.params.deleteAll=e.deleteAll),t.request(s,e)}))},e.removeItemThumbnail=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/deleteThumbnail`;return t.request(s,e)}))},e.removeNotification=async function(e){const n=await x(e),s=`${r(e)}/community/users/${n}/notifications/${e.id}/delete`;return t.request(s,e)},e.scrubControlChars=c,e.searchCommunityUsers=function(e){return y(e,"communityUser")},e.searchGroupContent=function(e){return y(e,"groupContent")},e.searchGroupUsers=function(e,n){const s=`${r(n)}/community/groups/${e}/userlist`,o=t.appendCustomParams(n||{},["name","num","start","sortField","sortOrder","joined","memberType"],{httpMethod:"GET"});return t.request(s,o)},e.searchGroups=function(e){return y(e,"group")},e.searchItems=I,e.searchUsers=function(e){return y(e,"user")},e.setItemAccess=async function(e){const t=await e.authentication.getUsername(),r=g(e,t);return l(e,t)?S(r,e):f(e).then((n=>{if(n)return S(r,e);throw Error(`This item can not be shared by ${t}. They are neither the item owner nor an organization admin.`)}))},e.setUserProperties=async function(e,n,s){const o=`${r(s)}/community/users/${encodeURIComponent(e)}/setProperties`,i=Object.assign({httpMethod:"POST",params:{properties:n}},s);try{const e=await t.request(o,i);if(!e.success)throw new Error("Success was false");return e}catch(e){throw new Error(`Failed to set user properties: ${e.message}`)}},e.shareItemWithGroup=async function(e){return C(e).then((async t=>{if(t)return{itemId:e.id,shortcut:!0,notSharedWith:[]};const{owner:r,confirmItemControl:n}=e,s=await e.authentication.getUsername(),o=r||s;if(o!==s){let t=!1,r=!1;return Promise.all([P({username:s,authentication:e.authentication}),P({username:o,authentication:e.authentication}),$(e)]).then((([s,o,i])=>{const a=!!n;return t="org_admin"===s.role&&!s.roleId,r=s.orgId!==o.orgId,function(e,t,r,n,s,o){const i=[];if(o.groupId!==e.favGroupId)if(t){if(!n)throw Error(`This item can not be shared to shared editing group ${o.groupId} by ${e.username} as they not the item owner or org admin.`);i.push(M(e,e,!1,`Error adding ${e.username} as member to edit group ${o.groupId}. Consequently item ${o.id} was not shared to the group.`,o),M(e,s,!0,"none"===r?`Error adding user ${s.username} to edit group ${o.groupId}. Consequently item ${o.id} was not shared to the group.`:`Error promoting user ${s.username} to admin in edit group ${o.groupId}. Consequently item ${o.id} was not shared to the group.`,o))}else if(n)i.push(M(e,e,!1,`Error adding ${e.username} as member to view group ${o.groupId}. Consequently item ${o.id} was not shared to the group.`,o));else if("none"===r)throw new Error(`This item can not be shared by ${e.username} as they are not a member of the specified group ${o.groupId}.`);return i}(s,a,i,t,o,e)})).then((n=>{const[{revert:s}={promise:Promise.resolve({notAdded:[]}),revert:e=>Promise.resolve(e)}]=n;return Promise.all(n.map((({promise:e})=>e))).then((()=>E(e,t,r))).then((e=>s(e)))}))}return E(e)})).then((t=>{if(t.notSharedWith.length)throw Error(`Item ${e.id} could not be shared to group ${e.groupId}.`);return t}))},e.unprotectGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/unprotect`;return t.request(n,e)},e.unprotectItem=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/unprotect`;return t.request(s,e)}))},e.unshareItemWithGroup=function(e){return C(e).then((async n=>{if(!n)return Promise.resolve({itemId:e.id,shortcut:!0,notUnsharedFrom:[]});const{owner:s}=e,o=await e.authentication.getUsername();return Promise.all([$(e),P({username:o,authentication:e.authentication})]).then((([n,i])=>{const a=(s||o)===o,u="org_admin"===i.role&&!i.roleId;if(!a&&!u&&["admin","owner"].indexOf(n)<0)throw Error(`This item can not be unshared from group ${e.groupId} by ${o} as they not the item owner, an org admin, group admin or group owner.`);return async function(e){const n=await e.authentication.getUsername(),s=e.owner||n;let o=`${r(e)}/content/items/${e.id}/unshare`;s===n&&(o=`${r(e)}/content/users/${s}/items/${e.id}/unshare`);return e.params={groups:e.groupId},t.request(o,e)}(e)})).then((t=>{if(t.notUnsharedFrom.length)throw Error(`Item ${e.id} could not be unshared to group ${e.groupId}`);return t}))}))},e.updateGroup=function(e){const n=`${r(e)}/community/groups/${e.group.id}/update`;return e.params=Object.assign(Object.assign({},e.params),e.group),t.request(n,e)},e.updateItem=i,e.updateItemInfo=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/updateinfo`;return e.params=Object.assign({folderName:e.folderName,file:e.file},e.params),t.request(s,e)}))},e.updateItemResource=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/updateResources`;return e.params=Object.assign({file:e.resource,fileName:e.name,resourcesPrefix:e.prefix,text:e.content},e.params),void 0!==e.private&&(e.params.access=e.private?"private":"inherit"),t.request(s,e)}))},e.updateUser=async function(e){const n=e.user.username||await e.authentication.getUsername(),s=`${r(e)}/community/users/${encodeURIComponent(n)}/update`;return e.params=Object.assign(Object.assign({},e.user),e.params),delete e.user,t.request(s,e)},e.updateUserMemberships=U,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=portal.umd.min.js.map